这个javascript/HTML出了什么问题

Dav*_*vid 1 javascript javascript-events

我想我只需要第二双眼睛.div的onclick事件似乎不起作用.有任何想法吗?

<!DOCTYPE html> 
<html> 
 <head>
 <meta charset="UTF-8">
 <title="My First Program"/>

 <script type="text/javascript">
      window.onload = function(){
           window.alert("If you see me then the page has loaded"); 
           click(); 
      }

      //we do programming here 
      /*because
        it is 
        fun*/
      window.alert("Helo World!"); 

      function click(){
           window.alert("CLICK!!!!");
      }


 </script>

 </head>
 <body>
      <div>This web page will run my first program</div>
      <!--this will be awesome-->
      <br>
      <br>
      <br>
      <div id="d1" onclick="click()">Click me</div>
 </body>
Run Code Online (Sandbox Code Playgroud)

另外,对于记录,这不是我的第一个程序.

Mik*_*ran 5

你的HTML格式不正确.标题标签需要如下所示:

<title>My First Program</title>
Run Code Online (Sandbox Code Playgroud)

此外,您似乎有一个命名冲突,因为您将您的函数命名为与内置函数相同的东西.将"点击"功能重命名为"myclick"或其他内容.

一旦你解决了这个问题,其他一切都应该是好的.

当事情变得奇怪时,你应该做的第一件事是验证你的标记.

http://validator.w3.org/check

这是标记的完整工作版本.

<!DOCTYPE html> 
<html> 
 <head>
 <meta charset="UTF-8">
 <title>My First Program</title>

 <script type="text/javascript">
      window.onload = function(){
           window.alert("If you see me then the page has loaded"); 
           click(); 
      }

      //we do programming here 
      /*because
        it is 
        fun*/
      window.alert("Helo World!"); 

      function myclick(){
           window.alert("CLICK!!!!");
      }


 </script>

 </head>
 <body>
      <div>This web page will run my first program</div>
      <!--this will be awesome-->
      <br>
      <br>
      <br>
      <div id="d1" onclick="myclick()">Click me</div>
 </body>
Run Code Online (Sandbox Code Playgroud)