Home  >  Article  >  Web Front-end  >  表单怎么进行验证?_html/css_WEB-ITnose

表单怎么进行验证?_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-21 09:40:37907browse

 <script type="text/javascript">             function checkNum() {                 return;             }  <form action="?step=2" method="post"> <button type="submit" class="mt15 redbtn" onclick="checkNum();">提交退换货申请     </button> </form>	

写成上面这样不起作用,照样提交到服务器

写成下面这样就有作用
 <form action="?step=2" method="post"> <button type="submit" class="mt15 redbtn" onclick="javascript:return false;">提交退换货申请     </button> </form>	

咋办呢?我要在checkNum()方法里面进行验证的


回复讨论(解决方案)

return confirm(这里面写的你函数);

因为你的按钮类型是submit。使用button就不会出现这个问题。另外你的<script>括起来啊。 </script>

不能用onclick,应该用onSubmit

不然人家用键盘怎么办?

另外应该是return checkNum();

谢谢大家,3楼说的对

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