0
jQuery插件。将其设置在输入上。JQuery插件不起作用
onkeydown
事件必须调用KeyDown
。但对于控制台的回应,我看到:
Uncaught TypeError: Object #<HTMLInputElement> has no method 'KeyDown'
在写插件我是一个新手。因为它是由jQuery的覆盖
;(function ($, window, document, undefined) {
function Plugin(element, options) {
var defaults = {
width: 270,
height: 300
};
this.element = element;
this.el = $(element);
this.options = $.extend({}, defaults, options) ;
this.init();
}
Plugin.prototype = {
init: function() {
this.el.on('keydown', function (e) { this.KeyDown(e); });
},
KeyDown: function (e) {
console.log('Yeah!!!');
}
};
$.fn.myplugin= function (options) {
return this.each(function() {
if (!$.data(this, 'plugin_myplugin')) {
$.data(this, 'plugin_myplugin',
new Plugin(this, options));
}
});
}
})(jQuery, window, document);
@soul,你甚至看这个问题? –
你有更多的代码可以看吗? HTML,以及您在哪里启动/包含插件。 – putvande