您好我havr與獲取事件並將其傳遞給閉合功能問題也是我想要的(這個)varaibleJavaScript獲取具有關閉功能的事件?
我使用
console.log(e);
其顯示未定義>>的SLOUTION什麼最好SLOUTION :)
我試試這個代碼
<script>
for(var i=0;i<a.length;i++){
a[i].addEventListener("keydown",(function(e){
return function(){
if (e.keyCode == 13 && !e.shiftKey){
console.log(e); // e its undefined this is the problem
console.log(i); // its get i value no problem here
//now iam use the closure for get i value
//var that = this;
}
};
})(e), false);
}
</script>
在你的上下文中,'this'應該指的是什麼? – Todd
電子應該是什麼......你的事件?然後,您想要將該函數作爲事件偵聽器*傳遞,而無需使用e調用該函數。 – Shashank
你的處理程序返回一個函數,該函數可以成功記錄事件,但那個返回的函數永遠不會被調用! – Bergi