javascript 提示submit is not a function錯誤

來源:互聯網
上載者:User

我遇到了一個很奇怪的問題,就是在利用Javascript控製表單提交時,瀏覽器提示document.genForm.submit is not a function。genForm是表單<form>的name,並且使用同樣函數的另一個表單卻執行正常,尋找了半天也沒有發現兩個有什麼不同,後來在網上搜尋了一番,結果找到了原因。

當表單<form>…</form>中含有name=”submit”時,提交時就會有衝突,這個錯誤常見於按鈕上,如:


在Javascript做submit()的時候就會出現衝突,這時將name=”submit”改成別的比如login之類的就可以了,反正submit在這個情況下是個保留關鍵字。


執行個體

<form name="detailForm" action="adminSearchPerformance.do" method="post">    <input type="hidden" value="${userPerformance.userId}" name="userId"/>     <input type="hidden" value="${userPerformance.userName}" name="teacherName"/>    <input type="hidden" value="1" name="admin"/>
</form> <a href="javascript:document.detailForm.submit();" class="a-comm">查看詳情</a></td>

解決辦法

<a href="javascript:document.getAll["detailForm"].submit();" class="a-comm">查看詳情</a></td>

有時候需要用javascript提交表單,很可能大家會用javascript:myForm.submit();可是在這樣做的時候怎麼也提交不成功,在FF中查看javascript錯誤Javascript Error: submit is not a function。其原因可能在於用myForm.submit()提交表單的時候,表單裡面含有name="submit"的元素,在提交的時候,該對象會和submit();方法發生混淆造成該錯誤!

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.