Javascript 提交返回false不起作用,表单仍然提交吗?
这是密码Javascript 提交返回false不起作用,表单仍然提交吗?,javascript,html,Javascript,Html,这是密码 <html> <head> <script> function test() { return false; } </script> </head> <body> <form method="post" action="../test.php"> &
<html>
<head>
<script>
function test() {
return false;
}
</script>
</head>
<body>
<form method="post" action="../test.php">
<input type="submit" onsubmit="return test()">
</form>
</body>
</html>
功能测试(){
返回false;
}
表单如何仍在提交,这对我来说毫无意义???当用户通过点击表单中的
submit
按钮提交表单时,您需要停止表单提交
将submit
按钮的onsubmit
更改为onclick
<input type = "submit" onsubmit= "return test()">
当用户通过单击表单中的
submit
按钮提交表单时,您需要停止表单提交
将submit
按钮的onsubmit
更改为onclick
<input type = "submit" onsubmit= "return test()">
功能测试(e){
e、 预防默认值();
返回false;
}
功能测试(e){
e、 预防默认值();
返回false;
}
Tushar要求您通过单击
onclick
更改onmousenter
。你试过了吗?@LostProgrammer答案仍然是一样的,我还添加了onsubmit
,检查更新的答案。Sar要求你通过onclick
更改onmousenter
。你试过了吗?@LostProgrammer答案还是一样的,我还添加了onsubmit
,检查更新的答案表单有onsubmit而不是按钮表单有onsubmit而不是按钮
<form method="post" action="../test.php" onsubmit="return test()">
<!-- ^^^^^^^^^^^^^^^^^^^^^^^^ -->
<input type="submit" />
</form>
<html>
<head>
<script>
function test(e) {
e.preventDefault();
return false;
}
</script>
</head>
<body>
<form method="post" action="../test.php" onsubmit="return test(event);">
<input type="submit">
</form>
</body>