jquery,我该如何避免这种选择器重复?

问题描述:

我有这样的功能:jquery,我该如何避免这种选择器重复?

$('#barcode').JsBarcode($('#barcode').attr("data-barcode"), { 
     format:"EAN" 
     displayValue:true 
     fontSize:10 
     height: 22 
     marginLeft: 10 
     marginRight: 10 
     marginTop: 3 
     marginBottom: 0 
     }) 

它的工作,但我想避免重复。我试着用this$this没有成功...

+0

'$ this'和'this'只能在函数的上下文中使用。 –

$('#barcode')是一个可以放入变量的对象。

var barcode = $('#barcode'); 
barcode.JsBarcode(barcode.attr("data-barcode") ..