且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Jquery在具有相同id的多个输入中检测按键

更新时间:2022-04-28 08:52:29

你应该为html元素设置唯一的id,你应该分配一个公共类和通过它访问。

You should have unique id for html elements you should assign a common class and access throug it.

现场演示

Live Demo

<input type="text" id="description1" name="1" class="commonclass">
<input type="text" id="description2" name="2" class="commonclass">
<input type="text" id="description3" name="3" class="commonclass">


 $('.commonclass').keypress(function(event){
       alert("keycode: " + event.keyCode);
       alert("id: " + this.id);
 });​