Property 'submit' of object #<HTMLFormElement> is not a function

<form action="" type="get" id="form">
    <input type="button" name="submit" id="subBtn" value="submit">
</form>

点击按钮,触发表单提交:

document.getElementById("subBtn").onclick=function(){
   document.getElementById("form").submit(); 
}

会报错(chrome下):

Uncaught TypeError: Property 'submit' of object #<HTMLFormElement> is not a function

 

原因是name="submit"这句,换成别的name=sb1,sb2,sb2。。。

 

另外,经测,将id="submit",也会这样

同理,用于reset

 

一句话!!:

在表单里,别用name="submit|reset" 或  id="submit|reset"

ps:今天遇到了此错误,纠结了半天,记录一下,以警醒。

原文地址:https://www.cnblogs.com/yqyongqing/p/3430525.html