在div标签之间使用head标签

时间:2013-03-04 13:06:43

标签: html

这是我在其工作中尝试的示例代码

 <html>
 <head>
 <style>
 <!--
  .execute { background-color: red; height: 25px; }
 -->
 </style>
  <script src="http://ajax.googleapis.com/ajax/libs/dojo/1.6.0/dojo/dojo.xd.js">
  </script>

<!-- Let's register a onClick handle for any .execute div. -->

</head>
 <body>
<div class="execute">
  <head>
   <script>
  dojo.ready(function()  // Dojo will run this after being initialized
  {
      // Get A list of all tags with id execute and add a event onClick
      dojo.query(".execute").connect("onclick", function(evt)
      {
          alert("Event triggered!");
          // ...
      });
  });
</script>
  </head>
<body>
  Click me 1
 </body>
  </div>
<br /><br />
<div class="execute">Click me 2</div>
 </body>
 </html>  

但如果我将其合并到另一个代码中,它会突出显示并作为无效代码。这意味着什么?

4 个答案:

答案 0 :(得分:2)

Ther是几个代码问题。 <head>代码后面的双<body>代码,HTML元素。

清理代码:

<html>
 <head>
 <style>
  .execute { background-color: red; height: 25px; }
 </style>
  <script src="http://ajax.googleapis.com/ajax/libs/dojo/1.6.0/dojo/dojo.xd.js"></script>
  <script>
  dojo.ready(function() { // Dojo will run this after being initialized
    // Get A list of all tags with id execute and add a event onClick
    dojo.query(".execute").connect("onclick", function(evt) {
      alert("Event triggered!");
      // ...
    });
  });
  </script>
</head>
 <body>
  <div class="execute">Click me 1</div>
  <br><br>
  <div class="execute">Click me 2</div>
 </body>
</html>

答案 1 :(得分:1)

<head>只应出现一次,直接在<html>下,而不在<body>内。

例外情况是嵌入在现有网页中的iframe,这些网页都有自己的文档结构。

答案 2 :(得分:1)

只需删除第二个<head>

为什么你有两个脑袋? <script>不必在<head> s。

您的文档中只能有一个<head>

答案 3 :(得分:1)

HTML页面的结构应如下所示:

<html>
<head>
<title></title>
</head>
<body>
</body>
</html>

虽然不一定如此,但大多数人都会在开始和结束标头标签中添加脚本标签。例如:

<html>
<head>
<title></title>
<script>

<!--This is where all your functions should be.-->

</script>
</head>
<body>
</body>
</html>
相关问题