Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
234 views
in Technique[技术] by (71.8m points)

html - Can I have attributes on closing tags?

There are many people that mark closing tags like this to help identify the closing tag that goes with an HTML tag:

<div id="header">
  <div id="logo">
    <a href="index.php">
      <img id="logoimg" src="images/as_logo.png" alt="Logo" border="0" />
    </a>
  </div> <!-- logo -->
</div> <!-- header -->

I was wondering if it is syntactically ok to do this:

<div id="header">
  <div id="logo">
    <a href="index.php">
      <img id="logoimg" src="images/as_logo.png" alt="Logo" border="0" />
    </a>
  </div id="logo">
</div id="header">

UPDATE: Here is the text from the spec on HTML5.3:

8.1.2.2. End tags
End tags must have the following format:

  1. The first character of an end tag must be a U+003C LESS-THAN SIGN character (<).
  2. The second character of an end tag must be a U+002F SOLIDUS character (/).
  3. The next few characters of an end tag must be the element’s tag name.
  4. After the tag name, there may be one or more space characters.
  5. Finally, end tags must be closed by a U+003E GREATER-THAN SIGN character (>).

8.1.2.3. Attributes
Attributes for an element are expressed inside the element’s start tag.

Note that attributes are only allowed on START TAGS.

using @jbyrds idea; using the HR tag allows you to see if you forgot the z attribute:

<div id="header">
  <div id="logo">
    <a href="index.php" id=link">
      <img id="logoimg" src="images/as_logo.png" alt="Logo" border="0" />
    </a><hr z="link">
  </div><hr z="logo">
</div><hr z="header">

Although this adds more text, 32 extra characters vs. the original or the tags having a hidden class, you can use CSS to hide them.

[z] {
    display: none;
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Short answer, No.

Use the comments instead.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...