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>
Here is a list of Javascript's reserved words.
As you can see, submit
is one of them !
来源:https://stackoverflow.com/questions/35395433/onsubmit-function-called-submit