There is a piece of HTML:
<input onclick="start();" type="button" value="Start!"/>
In Firefox and Chrome it invokes start
on click. However in IE9 it produces the error message: SCRIPT5002: Function expected
. Then I tried several different cases:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<script>
function start(){
alert("Let's start");
}
function stop(){
alert("Let's stop");
}
</script>
<input onclick="start();" type="button" value="Start!"/><br/> <!-- Failed : the main issue -->
<span onclick="start();">Start!</span><br/> <!-- Work -->
<input onclick="stop();" type="button" value="Stop!"/><br/> <!-- Work -->
<input onclick="start();" type="text" value="Start!"/><br/> <!-- Failed -->
<input onmouseover="start();" type="button" value="Start!"/><br/> <!-- Failed -->
</body>
</html>
- Original case: Failed (That's why I'm here.)
- Use a
span
instead ofinput
: Success - Use another function name: Success
- Use a different type: Failed
- Use
onmouseover
instead ofonclick
: Failed
I used debugger and it said start
is function start(){alert("Let's start");}
. Then I used alert(start)
and it said fileopen
.
As the result of test 3, I can easily work-around by changing the name, but I want to know why this error would happened in some cases but not happened in the others. Edit: Or the next best thing, other work-arounds without changing the names.