Onsubmit function called submit

2020-02-15 08:31发布

问题:

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:

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