我试图在innerHTML中插入HTML注释,但它不接受在IE8中。 FF工作正常。在innerHTML中插入注释
<html>
<head>
<title>testing</title>
<script language="javascript">
function testcmt() {
var el2 = document.createElement("div");
el2.innerHTML = "<!--Sample--><p>Sample</p>";
alert(el2.innerHTML);
}
</script>
</head>
<body id="BodyID">
<h2>Test</h2>
<input type="button" value="Sample" onmousedown="testcmt(); return false">
</body>
IE只显示<p>Sample</p>
和注释丢失。任何指针?
你不会希望看到的评论显示在屏幕上。你检查了dom检查器,看看它是否被添加? – 2013-02-21 15:30:36
我很好奇这个评论的目的是什么?因为在运行时添加,评论似乎没用。 – Joe 2013-02-21 15:31:07
另外,这可能是由于IE必须解析注释,比如'<! - [if lte IE 7]>' – Joe 2013-02-21 15:33:49