[英]stopping default submit action and trigger custom click on dynamically generated content
I am using leadpages.net for building popups for my site. 我正在使用leadpages.net为我的网站构建弹出窗口。 They provide an anchor link and a script file source to get the popup on your page. 它们提供了一个锚链接和一个脚本文件源,以在您的页面上显示弹出窗口。 I want to stop default action of form submission and fire my custom click event handler for processing data input as shown below. 我想停止表单提交的默认操作,并触发我的自定义click事件处理程序来处理数据输入,如下所示。
But below never gets executed; 但是下面永远不会被执行; tried all variations with the below code, even included event.preventDefault() and event.stopPropagation(). 尝试使用以下代码进行所有变体,甚至包括event.preventDefault()和event.stopPropagation()。 Please help; 请帮忙; any insights what I am might be lacking. 我可能缺少任何见解。 Thanks in advance!!! 提前致谢!!!
$('body').on('click', '#leadpages-form', function(event) {
event.preventDefault();
event.stopPropagation();
console.log("here");
});
You're currently listening for a click
on the form, not for the form to submit
. 您当前正在监听的是表单的click
,而不是表单的submit
。 Try something like this. 尝试这样的事情。
$('#leadpages-form').submit(function(event) {
event.preventDefault();
event.stopPropagation();
console.log("here");
});
Or, if your form is created dynamically, you'll have to do it similarly to your example. 或者,如果您的表单是动态创建的,则必须与示例类似。
//or document if the body is created dynamically as well
$('body').on('submit', '#leadpages-form', function(event) {
event.preventDefault();
event.stopPropagation();
console.log("here");
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.