简体   繁体   English

使用jQuery,我如何检测到哪个

[英]Using jQuery, how do I detect which <input type='image> was clicked in a form with multiple submit images?

Let's say we have this form: 假设我们有这种形式:

<form>
  <input type="text" name="some_name" value="val" id="some_name">
  <input type="image" value="action" alt="Add To Cart" name="add" src="/images/submit.gif">
  <input type="image" value="action" alt="Shop some more" name="return" src="/continue_shopping.gif">
</form>

How do I find the input that submitted the form? 如何找到提交表单的输入?

You could add IDs to your different input items : 您可以将ID添加到不同的输入项中:

<input id="SomeName" type="text" name="some_name" value="val" id="some_name">
<input id="AddCart" type="image" value="action" alt="Add To Cart" name="add" src="/images/submit.gif">
<input id="Return" type="image" value="action" alt="Shop some more" name="return" src="/continue_shopping.gif" />

And then, in your jQuery, access the events with 然后,在您的jQuery中,使用

    $("#Return").click(function(){
    //do your stuff
    });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何检测JavaScript中按下了哪个“表单输入类型=图像”? - How do I detect which Form Input Type=image was pressed in JavaScript? 如果单击提交,如何关闭输入 - How do I close the input if submit is clicked Dropzone,如何使用数据和多个图像提交表单? - Dropzone, how do I submit form with data and multiple images? 如何使多个图像在使用 jQuery 单击时消失? - How do I make multiple images disappear on being clicked using jQuery? 如何使用图像链接提交表单以使用JS(无JQuery)更改表单操作? - How do I submit a form using image links to change form action with JS (no JQuery)? 如何使用jQuery / JavaScript检测多组单选按钮更改并更改单独的表单输入? - How do I use jQuery/JavaScript to detect multiple sets of radio button changes and change a separate form input? 如何在我的 class 组件中检测在功能组件中单击了哪个输入值? - How do I detect in my class component which input value's clicked in functional component? 单击按钮后,如何通过POST请求提交表单输入数据? - How do I submit form input data with POST request when button is clicked? 单击提交输入类型时 jQuery 没有响应 - jQuery not responding when Submit input type is clicked 单击如何检测提交表单按钮 - How to detect submit form button was clicked
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM