jquery submit()不能提交表单的解决方法

原文地址为: jquery submit()不能提交表单的解决方法

 
   
  1. <form id="form" method="get">
  2. <input type="text" name="q" value="设计蜂巢"/><button type="button" id="submit">查询</button>
  3. </form>
  4. <script type="text/javascript">
  5. $(function(){
  6. $('#submit').click(function(){
  7. $('#form').submit()
  8. })
  9. })
  10. </script>

上述代码看上去貌似没什么问题,简直是普通了不能再普通的代码。可是点击查询按钮的时候死活不提交表单,按钮type改为submit表单提交正常。于是上JQUERY API查找原因,看到以下这段文字顿时明白了:

Additional Notes:
Forms and their child elements should not use input names or ids that conflict with properties of a form, such as submit, length, or method. Name conflicts can cause confusing failures. For a complete list of rules and to check your markup for these problems, see DOMLint.

其他注意事项:
表单和其子元素不宜用一个表单的属性的属性作为name或id的名称,如submit, length, or method,是、会产生冲突。名称冲突可能会导致混乱的失败。对于一个完整的规则列表,并检查这些问题标记,看DOMLint。

-_-^ 原来就是这个id=”submit”的原因,不知道你有木有犯这种低级的错误.


ps:就是要查看你的  <input type="button" class="gridViewHeader" name="submit"  value=" 提 交 " onclick="validateName('submit')"/> 这里面的 name 值 要改为 name="submit1" 就是不能为 " submit" 就OK啦


转载请注明本文地址: jquery submit()不能提交表单的解决方法

猜你喜欢

转载自blog.csdn.net/wcqlwyt/article/details/80723534