[英]object prototype function not working
我不能以這種方式使用對象原型嗎?
Object.prototype.keyPressed = function(){
var key = (this.keyCode ? this.keyCode : this.which);
return key;
};
$(document).on('keypress'), function(e){
if (e.keyPressed() != 13) return;
});
您可以通過這種方式進行操作,但是會出現語法錯誤:
$(document).on('keypress'), function(e){
if (e.keyPressed() != 13) return;
});
應該
$(document).on('keypress', function(e){
if (e.keyPressed() != 13) return;
});
注意'keypress'
之后的額外)
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.