HTML 注解 PHP

代码

<!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" >
<head>
<title>无标题页</title>
</head>
<body>
<!--haha&#13;ha--><!sllsdfjalsdfjasdf>
<span id="span1" title="<!--haha&#10;&#13;h\r\na-->">sss</span>
<script type="text/javascript">
alert(document.getElementsByTagName(
'*').length); //所有元素个数,IE包含注解
if(document.getElementsByTagName('!').length > 0)
{
alert(document.getElementsByTagName(
'!')[1].data);
}
alert(document.documentElement.outerHTML);
//获取HTML的源码
alert(document.getElementById('span1').title);//innerHTML包含注解,innerText不包含注解
</script>
</body>
</html>

结论

HTML注解 <!--haha&#13;ha--><!sllsdfjalsdfjasdf> 均可

使用 document.getElementsByTagName('*') 获取所有网页元素时,IE(IE9非兼容模式不包含)包含注解。

IE中获取注解的方法 document.getElementsByTagName('!')

在 <span id="span1" title="<!--haha&#10;&#13;h\r\na-->">sss</span> 中不算注解 在title中回车可用 &#10;&#13;

获取当前网页源码 document.documentElement.outerHTML




欢迎转载,转载请注明:转载自[ http://www.cnblogs.com/zjfree/ ]
原文地址:https://www.cnblogs.com/zjfree/p/2219212.html