我正在编写我的第一个 jQuery 插件。我正在尝试添加悬停动作,但会立即调用悬停响应。这是我的插件:
(function($){
var Help = function(element, options) {
this.$element = element;
this.options = $.extend({}, $.fn.help.defaults, options);
};
Help.prototype.hover = function(name){
alert(name);
};
$.fn.help = function(option){
return this.each(function () {
var $this = $(this);
var help = $this.data('help');
var options = "";
var data = $this.data('help-id');
if(!help) {
$this.data('help', (help = new Help(this, options)));
}
$this.on('hover', help.hover(data));
});
};
})(jQuery);
我附加了我的插件$('#one').help()
,但这会立即调用悬停功能。我究竟做错了什么?