方法錯誤我使用下面的代碼,但它返回以下錯誤對象有沒有在JavaScript
Uncaught TypeError: Object [object HTMLAnchorElement] has no method 'userInput'
這裏是代碼jsfiddle
var ClickEvent = function (event) {
this.ev = $('.' + event);
this.ev.on('click', function() { this.userInput(); });
};
ClickEvent.prototype = function() {
return {
userInput: function() {
console.log('user');
},
show: function() {
console.log('show');
}
};
}();
var c = new ClickEvent('event');
我打電話userInput
函數內部on()
回調函數,但返回error
以上。
我該如何解決這個問題?
在click事件處理程序函數(您現在有userInput的地方)中放置了一個'console.log(this)'。它告訴你什麼? :) –
是'$'jQuery?如果是,請添加標籤。 – epascarello