2017-10-20 84 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

由于它的作品! –