当js运行时报错Uncaught TypeError: test is not a function at HTMLButtonElement.onclick如下面代码:
<form action="">
<button type="button" onclick=test() id="test">搜索</button>
</form>
<script>
function test(){
alert("success")
}
</script>
错误的原因在于有组件的id或者name与JavaScript函数的名称重复了,浏览器自动根据组件的name或id将函数解释为了组件,所以报错找不到函数。
解决办法就是组件的name和id不要和js的函数名一致