开发者

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

开发者 https://www.devze.com 2023-01-04 07:42 出处:网络
Let\'s say we have this form: <form> <input type=\"text\" name=\"some_name\" value=\"val\" id=\"some_name\">

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 :

<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

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

精彩评论

暂无评论...
验证码 换一张
取 消