Home  >  Article  >  Backend Development  >  先问个简短的阻止表单提交的问题

先问个简短的阻止表单提交的问题

WBOY
WBOYOriginal
2016-06-20 12:34:06989browse

刚才那个问题没有解决呢  我先用一个简短的例子做了个实验
我在网上看的说下面的代码不会提交过去 为什么我试了能提交过去呢?
我把form的onsubmit直接改成"return false"这样提交不过去 但是例子里面的可以提交过去  网上也有很多这样的例子 我试了怎么都能提交过去呢?这是为什么?

<!DOCTYPE html><html><head>	<title></title>	<script type="text/javascript">    function check(){      return false;    }</script></head><body><form onsubmit="check()"><input type="submit" value="点击表单不会提交" /></form></body></html>


回复讨论(解决方案)

为了清晰起见,加了点代码

<!DOCTYPE html><html><head>    <title></title>    <script type="text/javascript">    function check(){      return false;    }</script></head><body><form onsubmit="check()"><input type="submit" name=test value="点击表单不会提交" /></form></body></html><?phpprint_r($_GET);

显然与你的预期不一样
当将 onsubmit="check()"
改为 onsubmit=" return check()"
表单就不能提交
个中原因你自己琢磨琢磨吧

为了清晰起见,加了点代码

<!DOCTYPE html><html><head>    <title></title>    <script type="text/javascript">    function check(){      return false;    }</script></head><body><form onsubmit="check()"><input type="submit" name=test value="点击表单不会提交" /></form></body></html><?phpprint_r($_GET);

显然与你的预期不一样
当将 onsubmit="check()"
改为 onsubmit=" return check()"
表单就不能提交
个中原因你自己琢磨琢磨吧


一开始时这两种方法我都试了 onsubmit="check()"   onsubmit="return check()"  都不行  都是可以提交的  onsubmit="如果直接写return false"就提交不了  点击按钮没有任何反应  如果阻止提交都应该是没有任何反应吧   别人试了onsubmit="return check()" 说可以阻止提交 我试的就可以提交  而且地址栏有变化 并不是点按钮一点反应没有 这为什么  为什么我的结果跟被人不一样?


那你应该贴出真实代码

那你应该贴出真实代码



这就是真实代码啊 没有别的代码

你的这个代码就是能提交的!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn