如何检测使用jQuery点击哪个按钮 [英] how to detect which button is clicked using jQuery

查看:90
本文介绍了如何检测使用jQuery点击哪个按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何检测使用jQuery点击哪个按钮

 < div id =dBlock> 
< div id =dCalc>
< input id =firstNumbertype =textmaxlength =3/>
< input id =secondNumbertype =textmaxlength =3/>
< input id =btn1type =buttonvalue =Add/>
< input id =btn2type =buttonvalue =Subtract/>
< input id =btn3type =buttonvalue =Multiply/>
< input id =btn4type =buttonvalue =Divide/>
< / div>
< / div>

注意:上面的dCalc块是动态添加的...


点击(功能(e){
var idClicked = e.target

  $(input .id; 
});


how to detect which button is clicked using jQuery

<div id="dBlock">
 <div id="dCalc">
  <input id="firstNumber" type="text" maxlength="3" />
  <input id="secondNumber" type="text" maxlength="3" />
  <input id="btn1" type="button" value="Add" />
  <input id="btn2" type="button" value="Subtract" />
  <input id="btn3" type="button" value="Multiply" />
  <input id="btn4" type="button" value="Divide" />
 </div>
</div>

Note: above "dCalc" block is added dynamically...

解决方案

$("input").click(function(e){
    var idClicked = e.target.id;
});

这篇关于如何检测使用jQuery点击哪个按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆