在div标签之间使用head标签

时间:2023-02-10 20:32:31

this is sample code i tried n its working

这是我尝试过的示例代码

 <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>  

but if i merge it in another code it highlights and as invalid code. what does it means?

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

4 个解决方案

#1


1  

<head> should only appear once, directly under the <html>, and not within <body>.

应该只出现一次,直接在下面,而不是在中。

Exceptions to this are iframes embedded within existing pages, which have their own document structure.

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

#2


2  

Ther are several code issues. double <head> tags, HTML elements after the <body> tag.

有几个代码问题。 double 标记,标记之后的HTML元素。

cleaned up code:

清理代码:

<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>

#3


1  

Just remove the second <head>.

只需删除第二个。

Why do you have two heads? <script>s don't have to be in <head>s.

为什么你有两个脑袋?

You should only have a single <head> in your document.

您的文档中只应该有一个。

#4


1  

The structure of an HTML page should be as follow:

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

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

Although they do not have to be, most people put script tags within the opening and closing header tags. For example:

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

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

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

</script>
</head>
<body>
</body>
</html>

#1


1  

<head> should only appear once, directly under the <html>, and not within <body>.

应该只出现一次,直接在下面,而不是在中。

Exceptions to this are iframes embedded within existing pages, which have their own document structure.

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

#2


2  

Ther are several code issues. double <head> tags, HTML elements after the <body> tag.

有几个代码问题。 double 标记,标记之后的HTML元素。

cleaned up code:

清理代码:

<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>

#3


1  

Just remove the second <head>.

只需删除第二个。

Why do you have two heads? <script>s don't have to be in <head>s.

为什么你有两个脑袋?

You should only have a single <head> in your document.

您的文档中只应该有一个。

#4


1  

The structure of an HTML page should be as follow:

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

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

Although they do not have to be, most people put script tags within the opening and closing header tags. For example:

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

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

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

</script>
</head>
<body>
</body>
</html>