运行 JavaScript 表单提交后(Wordpress + WPPayForm)
Run JavaScript after Form Submit (Wordpress + WPPayForm)
我的 Wordpress 页面上有一个付款表格,我想在表格提交后 运行 一个 javascript 代码。
这是我要提交的代码:
ny.track({name: (new URL(window.location.href)).searchParams.get("utm_source"), value: 24.50, unit: "CHF"})
这是我的 Wordpress 页面上的内容:
jQuery(".wpf_submit_button").submit(function() {
ny.track({name: (new URL(window.location.href)).searchParams.get("utm_source"), value: 24.50, unit: "CHF"});
});
不幸的是,这似乎不起作用。如果我将其更改为在 click 上触发(例如 jQuery(".wpf_submit_button").click(function...
那么它可以正常工作,所以我不确定我做错了什么。Here is the link to a testpage with the code implemented. I am using WPPayForm 付款表格。
非常感谢任何帮助!
.submit()
根据 jQuery 文档绑定到“提交”javascript 事件。您应该使用表单 ID 而不是按钮 class 作为 jQuery 选择器:
jQuery("#wpf_form_id_354").submit(function() {
ny.track({name: (new URL(window.location.href)).searchParams.get("utm_source"), value: 24.50, unit: "CHF"});
});
检查 jQuery 文档:https://api.jquery.com/submit/
The submit
event is sent to an element when the user is attempting
to submit a form. It can only be attached to <form>
elements.
我的 Wordpress 页面上有一个付款表格,我想在表格提交后 运行 一个 javascript 代码。
这是我要提交的代码:
ny.track({name: (new URL(window.location.href)).searchParams.get("utm_source"), value: 24.50, unit: "CHF"})
这是我的 Wordpress 页面上的内容:
jQuery(".wpf_submit_button").submit(function() {
ny.track({name: (new URL(window.location.href)).searchParams.get("utm_source"), value: 24.50, unit: "CHF"});
});
不幸的是,这似乎不起作用。如果我将其更改为在 click 上触发(例如 jQuery(".wpf_submit_button").click(function...
那么它可以正常工作,所以我不确定我做错了什么。Here is the link to a testpage with the code implemented. I am using WPPayForm 付款表格。
非常感谢任何帮助!
.submit()
根据 jQuery 文档绑定到“提交”javascript 事件。您应该使用表单 ID 而不是按钮 class 作为 jQuery 选择器:
jQuery("#wpf_form_id_354").submit(function() {
ny.track({name: (new URL(window.location.href)).searchParams.get("utm_source"), value: 24.50, unit: "CHF"});
});
检查 jQuery 文档:https://api.jquery.com/submit/
The
submit
event is sent to an element when the user is attempting to submit a form. It can only be attached to<form>
elements.