[英]Form onsubmit preventDefault() not working
When on submitting the below form it always reloads with parameters in url.Don't know why this is happening:提交以下表单时,它总是重新加载 url 中的参数。不知道为什么会这样:
$html .=
'<form method="post" id="mailchimp">
<input type="text" name="fname" placeholder="First name" />
<input type="text" name="lname" placeholder="Last name" />
<input type="email" name="email" placeholder="Email *" required />
<button type="submit" id="mailchimp_submit">Subscribe</button>
</form>';
and jquery is below jquery 在下面
jQuery(document).ready(function() {
jQuery('#mailchimp').on('submit', function(e){
console.log('submitting');
e.preventDefault();
});
});
It neither console logs nor prevent loading.It just keeps loading?Anything i am wrong with any coding?它既不控制台日志也不阻止加载。它只是继续加载?我对任何编码有什么问题吗?
I Think you haven't added the JQuery path.我认为您尚未添加 JQuery 路径。 I test this code and it works fine
我测试了这段代码,它工作正常
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.