1. 程式人生 > >jquery submit()不能提交表單的解決方法

jquery submit()不能提交表單的解決方法

  1. <formid="form"method="get">
  2. <inputtype="text"name="q"value="設計蜂巢"/><buttontype="button"id="submit">查詢</button>
  3. </form>
  4. <scripttype="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啦