2017-10-20 88 views
1

我使用jQuery:如何確定哪些多個按鍵綁定是被解僱

$("input[name='first'], input[name='second'], 
input[name='third']").bind("keypress", function(e) { 

     //how to determine which input is being entered 

}); 

我有3個輸入字段, 我想知道如何辨別和確定哪個輸入值是「打字」基於上述功能。

回答

1

我們可以使用關鍵字this

$("input[name='first'], input[name='second'], input[name='third']").bind("keypress", function(e) { 
console.log(this); 
alert(this.name); 
}); 

working fiddle here

+1

由於它的作品! –