Onsubmit function called submit

2020-02-15 08:48发布

I am wondering why onsubmit global scoped function cannot be called submit. I didnt find any reason.

This doesnt work:

<form onsubmit="return submit();">
    <input type="submit">
</form>
<script>
    function submit() { alert('Hey!'); return false; }
</script>

This does work:

<form onsubmit="return test();">
    <input type="submit">
</form>
<script>
    function test() { alert('Hey!'); return false; }
</script>

1条回答
时光不老,我们不散
2楼-- · 2020-02-15 09:11

Here is a list of Javascript's reserved words. As you can see, submit is one of them !

查看更多
登录 后发表回答