开发者

Javascript Fails to Execute

开发者 https://www.devze.com 2023-04-02 05:33 出处:网络
For even a simple block of inline JavaScript in an HTML page, such as: <script type=\"text/javascript\">

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
0

精彩评论

暂无评论...
验证码 换一张
取 消