preventDefault在提交按钮中不起作用 [英] preventDefault not work in submit button
本文介绍了preventDefault在提交按钮中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有 html
表单,当我点击提交
按钮页面转到insert.php
I不要它
preventDefoult不工作
我有这个脚本
html
I have html
form and when I clicked submit
button page goes to insert.php
I don't wont it
preventDefoult don't work
I have this script
html
HTML
<form action="insert.php" method="post">
<input type="text" name="username" placeholder=""><br />
<input type="text" name="name" placeholder=""><br />
<input type="text" name="lastname" placeholder=""><br />
<input id="mail" name="email" type="text" placeholder="E-mail"><br />
<input id="mail_1" type="text" placeholder="reply E-mail"><br />
<input id="password" name="password" type="password" placeholder=""><br />
<input id="password_1" type="password" placeholder=""><br />
<input id="submit" type="submit" value="registration">
</form>
jquery
$("#submit").click(function(event){
event.preventDefault();
});
推荐答案
而不是听按钮点击你需要听对于< form>
提交:
Instead of listening for the button click you need to listen for <form>
submit:
$("form").submit(function(event){
event.preventDefault();
});
现代jQuery(1.7或更高版本):
Modern jQuery (1.7 or later):
$("form").on('submit', function(event){
event.preventDefault();
});
这篇关于preventDefault在提交按钮中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文