从按钮附加ID单击到现有的jQuery函数,该函数可切换表单
我有一个表,每行都以动态生成的按钮结束。该按钮的ID与DB的用户ID匹配。我希望能够按任何按钮并将该ID传递给切换表单的脚本。我只是无法确定如何将ID附加到现有脚本以切换表单上。
到目前为止,我拥有的代码是
<button type='submit' class='btn btn-success' id='formButton$uid' onclick='myFunction()'>Edit User #$uid</button>
&amp;
$(document).ready(function() {
$("#3").click(function() {
$("#form1").toggle();
});
});
如您在上面的代码中所看到的,我对3中的ID进行了硬编码,但是正如我所说的那样,我正在寻找该ID以从任何按钮中获取值,ID,因此,如果有50个按钮,则可以全部切换。按钮单击ID时的表单将附加到jQuery切换函数中。
I have a table, each row is ended with a dynamically generated button. That button has an id matching the id of the user from the DB. I want to be able to press any of the buttons and pass that id to a script that toggles a form. I just cannot work out how to append the id to an existing script to toggle the form.
So far the code I have is
<button type='submit' class='btn btn-success' id='formButton$uid' onclick='myFunction()'>Edit User #$uid</button>
&
$(document).ready(function() {
$("#3").click(function() {
$("#form1").toggle();
});
});
As you see in the code above I have hard coded the id of 3 in but as I say I am looking for that id to take the value, the id, from any of the buttons clicked so if there are 50 buttons they can all toggle the form as the button clicked id will have be appended into the JQuery toggle function.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
几个小时后,我设法将ID添加到jQuery中。
那
我不知道这是否是完成这项工作的最佳方法?
After a few hours I have managed to add the id to the JQuery.
Then the JQuery
I don't know if this is the best way of doing the job?
您可以在元素名称上挂起单击事件,例如
[https://jsfiddle.net/bjq5drwh/2/]
我希望这会有所帮助
you could hook the on click event on the element name like so
[https://jsfiddle.net/bjq5drwh/2/]
I hope this helps