For example:
例如:
<div id="myDiv" />
Something would then be done to populate this div
using Javascript.
然后将使用Javascript填充此div。
Is this valid HTML?
这是有效的HTML吗?
6 个解决方案
#1
37
No. HTML 4.x doesn't have any concept of self closing tags.
不,HTML 4.x没有任何自闭标签的概念。
It is valid in XHTML.
它在XHTML中有效。
#2
11
Div's are not valid self closing tags. To have an empty div it would be better to do this:
Div不是有效的自闭标签。要有一个空div,最好这样做:
<div id="myDiv"></div>
#3
9
According to the XML declaration and the XHTML 1.0 and 1.1 document definitions, this is fine: the null-end tag (>
) may be used when immediately following the null-end start tag closer (/
), and your code is equivalent to <div id="myDiv"></div>
.
根据XML声明和XHTML 1.0和1.1文档定义,这很好:当紧跟在null-end开始标记close(/)之后可以使用null-end标记(>),并且你的代码等同于< div id =“myDiv”> 。
It's a different matter entirely whether any particular consumer will be able to process this correctly.
完全不同的是,任何特定的消费者是否能够正确处理这个问题。
The SGML declaration used by HTML 4.01 allows tag shortening, but it has a different syntax for the null-end tags; there you can write <div id="abc"/this is a non-empty div/
. Again, mileage may vary as for browser support. (My money is on "none".)
HTML 4.01使用的SGML声明允许标记缩短,但它对null-end标记有不同的语法;在那里你可以写
Future versions of HTML (HTML5? if that name is still alive) are no longer implemented as SGML languages, and therefore they simply allow what they say they do, without recourse to a formal grammar.
HTML的未来版本(HTML5?如果该名称仍然存在)不再作为SGML语言实现,因此它们只是允许他们所说的内容,而无需使用正式语法。
#4
3
Self Closing Tags in XHTML as implaied by browsers:
XHTML中的自闭关标签由浏览器植入:
What are all the valid self-closing elements in XHTML (as implemented by the major browsers)?
XHTML中有哪些有效的自闭元素(由主流浏览器实现)?
Self Closing tags in html5:
html5中的Self Closing标签:
Are (non-void) self-closing tags valid in HTML5?
(非空)自动关闭标签在HTML5中有效吗?
#5
1
I ran these two blocks of code through the W3C validator. Copy and paste the code into the input under the Validate by Direct Input tab to see the results for yourself.
我通过W3C验证器运行了这两个代码块。将代码复制并粘贴到“直接输入验证”选项卡下的输入中,以查看自己的结果。
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>title</title>
<meta http-equiv="content-type" content="text/html;charset=UTF-8" >
</head>
<body><div id="Mydiv" /></body>
</html>
The code block with Doctype of transitional HTML 4.01 failed the validation process.
Doctype为过渡HTML 4.01的代码块未通过验证过程。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<title>Test</title>
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
</head>
<body><div id="Mydiv" /></body>
</html>
When I added the XHTML 1.0 transitional doctype, changed the meta tag to a self closing tag, and added in the html xmlns line, the validation passed.
当我添加XHTML 1.0过渡文档类型时,将元标记更改为自闭标记,并在html xmlns行中添加,验证通过。
So to answer the first half of your question, it is valid HTML under the XHTML 1.0 Transitional doctype. Whether or not you can use javascript to properly populate it, I am not sure.
因此,要回答问题的前半部分,它是XHTML 1.0 Transitional doctype下的有效HTML。无论你是否可以使用javascript来正确填充它,我都不确定。
#6
0
No, it's valid XML (not HTML), and as far as I know, will only be accepted if the document is send with an application/xml mimetype.
不,它是有效的XML(不是HTML),据我所知,只有在使用application / xml mimetype发送文档时才会被接受。
However, it may work with XHTML, and the XHTML Doctype declaration.
但是,它可以与XHTML和XHTML Doctype声明一起使用。
#1
37
No. HTML 4.x doesn't have any concept of self closing tags.
不,HTML 4.x没有任何自闭标签的概念。
It is valid in XHTML.
它在XHTML中有效。
#2
11
Div's are not valid self closing tags. To have an empty div it would be better to do this:
Div不是有效的自闭标签。要有一个空div,最好这样做:
<div id="myDiv"></div>
#3
9
According to the XML declaration and the XHTML 1.0 and 1.1 document definitions, this is fine: the null-end tag (>
) may be used when immediately following the null-end start tag closer (/
), and your code is equivalent to <div id="myDiv"></div>
.
根据XML声明和XHTML 1.0和1.1文档定义,这很好:当紧跟在null-end开始标记close(/)之后可以使用null-end标记(>),并且你的代码等同于< div id =“myDiv”> 。
It's a different matter entirely whether any particular consumer will be able to process this correctly.
完全不同的是,任何特定的消费者是否能够正确处理这个问题。
The SGML declaration used by HTML 4.01 allows tag shortening, but it has a different syntax for the null-end tags; there you can write <div id="abc"/this is a non-empty div/
. Again, mileage may vary as for browser support. (My money is on "none".)
HTML 4.01使用的SGML声明允许标记缩短,但它对null-end标记有不同的语法;在那里你可以写
Future versions of HTML (HTML5? if that name is still alive) are no longer implemented as SGML languages, and therefore they simply allow what they say they do, without recourse to a formal grammar.
HTML的未来版本(HTML5?如果该名称仍然存在)不再作为SGML语言实现,因此它们只是允许他们所说的内容,而无需使用正式语法。
#4
3
Self Closing Tags in XHTML as implaied by browsers:
XHTML中的自闭关标签由浏览器植入:
What are all the valid self-closing elements in XHTML (as implemented by the major browsers)?
XHTML中有哪些有效的自闭元素(由主流浏览器实现)?
Self Closing tags in html5:
html5中的Self Closing标签:
Are (non-void) self-closing tags valid in HTML5?
(非空)自动关闭标签在HTML5中有效吗?
#5
1
I ran these two blocks of code through the W3C validator. Copy and paste the code into the input under the Validate by Direct Input tab to see the results for yourself.
我通过W3C验证器运行了这两个代码块。将代码复制并粘贴到“直接输入验证”选项卡下的输入中,以查看自己的结果。
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>title</title>
<meta http-equiv="content-type" content="text/html;charset=UTF-8" >
</head>
<body><div id="Mydiv" /></body>
</html>
The code block with Doctype of transitional HTML 4.01 failed the validation process.
Doctype为过渡HTML 4.01的代码块未通过验证过程。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<title>Test</title>
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
</head>
<body><div id="Mydiv" /></body>
</html>
When I added the XHTML 1.0 transitional doctype, changed the meta tag to a self closing tag, and added in the html xmlns line, the validation passed.
当我添加XHTML 1.0过渡文档类型时,将元标记更改为自闭标记,并在html xmlns行中添加,验证通过。
So to answer the first half of your question, it is valid HTML under the XHTML 1.0 Transitional doctype. Whether or not you can use javascript to properly populate it, I am not sure.
因此,要回答问题的前半部分,它是XHTML 1.0 Transitional doctype下的有效HTML。无论你是否可以使用javascript来正确填充它,我都不确定。
#6
0
No, it's valid XML (not HTML), and as far as I know, will only be accepted if the document is send with an application/xml mimetype.
不,它是有效的XML(不是HTML),据我所知,只有在使用application / xml mimetype发送文档时才会被接受。
However, it may work with XHTML, and the XHTML Doctype declaration.
但是,它可以与XHTML和XHTML Doctype声明一起使用。