Javascript Fails to Execute
For even a simple block of inline JavaScript in an HTML page, such as:
<script type="text/javascript">
var Hi= "Hi";
function SayHi ()
{
alert(Hi);
}
</script>
any browser that I test this code in (Chrome, 开发者_运维问答IE, Mozilla etc) fails to execute this code. I can only assume that something must have been disabled for Javascript not to run, however I am completely clueless as to the cause of this problem.
Any suggestions would be greatly appreciated.
You've defined the function and the variable to alert but you have not called the function.
<script type="text/javascript">
var message = "Hi";
function sayHi()
{
alert(message);
}
sayHi(); // Call the function.
</script>
you are not calling the function. add a call to that function before script closing tag
SayHi();
</script
精彩评论