且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

当AJAX请求完成时,如何在按钮上设置data- *属性?

更新时间:2023-11-20 23:14:40

请改用jquery data:

Use jquery data instead:

$("#submitForm").data('transaction', transactionID);

还有

var number_id = $("#submitForm").data('transaction');

请注意,这不会将属性添加到DOM,如果您通过开发人员工具检查元素,则不会看到data-transaction,但是元素将引用数据.

Notice that this will not add the attribute to the DOM, if you inspect the element via the developers tool, you won't see data-transaction, but the element will have the data referenced.

您的方法也应该起作用,但是正如@Tushar指出的那样,您缺少选择器中的#:$("submitForm")-> $("#submitForm")

Your method should also work, but as @Tushar pointed out, you are missing the # from your selector: $("submitForm") -> $("#submitForm")