简体   繁体   中英

Javascript does not seem to work in chrome

I'm having a tough time enabling javascript in chrome on my own webpage. Other websites seem to be able to do it pretty easily. Here's my prtty simple code but the start() function just wouldn't work.

<doctype html>
<html>
<head>
    <script type = "javascript">
        function start() {
            alert("Hi");
        }
    </script>
</head>
<body onload = "start()">
    Hi
</body>
</html>

You're using wrong type Attribute , it should be

<script type="text/javascript">

or simply

<script> </script>  //by default is type is "text/javascript"

Also change <!DOCTYPE html>

The main problem is your type attribute. If you were to keep it, then it should be

<script type="text/javascript"></script>

However, you don't need it (See here: http://javascript.crockford.com/script.html ). You can just use

<script></script>

That will fix your function.

Although not directly hindering your function, your doctype is missing the '!' and should probably be updated

<!doctype html>
<!doctype html>
<html>
<head>
  <script>
        function start() {
            alert("Hi");           
        }
    </script>
</head>
<body onload = "start()">
    Hi
</body>
</html>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM