开发者

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 :

<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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜