jQuery:如何选择唯一的ID?

发布于 2024-09-04 11:25:05 字数 326 浏览 4 评论 0原文

整个 jQuery(以及 javascript,呵呵)都是新的,到目前为止它非常好,但现在我陷入了困境。 假设我有从 SQL 数据库生成的表单列表,并且每个表单都必须具有唯一的 id,那么我如何选择要操作的特定项目(通过 php 更改值)。

$("#submit").click(function()) 将触发页面上的每个提交按钮,那么我如何才能将 #submit 成为我单击的某个随机 ID。可能有更聪明的方法,但我对此很陌生,所以请耐心等待。

想过用 onClick="myfunction(unique_id)" 传递唯一值,但不知道它如何与 jQuery 配合使用。

希望这有意义

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 this 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

零度° 2024-09-11 11:25:05

$("#submit") 不会拦截每个提交按钮的点击,而只会拦截 id="submit" 的元素。

如果您想获取表单的 id 属性,您可以使用如下代码片段:

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

$("#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');
});
淡笑忘祈一世凡恋 2024-09-11 11:25:05

我可能没有正确理解这个问题,但如果每个提交按钮都有一个唯一的 id,例如 那么 jQuery 将是 $("#submit_02").click(function() {})

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() {}).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文