开发者

jQuery: how to pick unique IDs?

开发者 https://www.devze.com 2023-01-02 07:31 出处:网络
New to whole this jQuery (and javascript altogether, heh) and so far it\'s been excellent, but now I\'m in a small pickle.

New to whole this jQuery (and javascript altogether, heh) and so far it's been excellent, but now I'm in a small pickle. Let's say I have list of forms generated from SQL database and every single one of them has to have unique id, so how I can select the specific item that is to be manipulated (changing values via php).

the $("#submit").click(function()) will trigger every submit buttons on the page, so how I can the #submit to be some random id that I clicked. There might be a smarter way, but I'm new to th开发者_运维问答is so try to bear with me.

thought of passing the unique value with onClick="myfunction(unique_id)", but don't know how it goes with jQuery.

hope this made any sense


$("#submit") won't intercept every submit button click, but only the element with id="submit".

If you want to get the form's id attribute you can use a snippet like this:

$("form").submit(function () { 
 var selectedFormID = $(this).attr('id');
});


I might not be understanding the question correctly but if each of the submit buttons has a unique id, e.g. <button id="submit_02">Submit</button> then the jQuery would be $("#submit_02").click(function() {}).

0

精彩评论

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