在previous question上没有得到答案时,我决定继续使用这个插件结构。
(function ( $ ) {
$.fn.myPlugin = function (options) {
options = $.extend( {}, $.fn.myPlugin.defaults, options );
return this.each(function (i, el) {
("someiD").live("click",function() {
UpdateCounter();
});
});
};
$.fn.myPlugin.defaults = {
///options here for overiding
};
}(jQuery));
我已经制作了一个插件,我必须选择一个按钮来增加一个计数器,然后我不知道如何获得OnSelect / OnClick按钮的计数器的更新值....任何人都可以在不改变我的插件结构的情况下,给我任何关于如何处理这个问题的见解?
答案 0 :(得分:1)
基本上是这样的:
(function ( $ ) {
$.fn.myPlugin = function (options) {
options = $.extend( {}, $.fn.myPlugin.defaults, options );
// $(this) is your selected element, #someSelect in this case
$(this).on('select', function(e) {
console.log('selected!')
})
};
// execute your plugin on the selected element
$('#someSelect').myPlugin();