简体   繁体   English

如何调用函数并通过jquery传递变量?

[英]How do I call a function and pass a variable with jquery?

I'm trying to do something like 我正在尝试做类似的事情

<button onclick="editUser('<?=id?>')">

I have a jquery function that updates the database with Ajax, but trying to tell the function which Id to update. 我有一个用Ajax更新数据库的jquery函数,但是试图告诉该函数要更新的ID。

Make the HTML something like this instead: 使HTML如下所示:

<button id="myButton" data-id="12345678">

When your page loads you'd do: 页面加载后,您可以执行以下操作:

$("#myButton").click(editUser);

Then in editUser() 然后在editUser()

var id = $(this).data("id");

Your function now knows the ID you're interested in. 您的函数现在知道您感兴趣的ID。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM