案例:javascript案例     状态:可编辑再运行    进入竖版
 运行结果 
x
 
1
<!DOCTYPE html>
2
<html>
3
<body>
4
5
<p id="demo">请点击按钮来查看 body 元素是否拥有属性。</p>
6
7
<button onclick="myFunction()">试一下</button>
8
9
<script>
10
function myFunction()
11
{
12
var x=document.getElementById("demo");
13
x.innerHTML=document.body.hasAttributes();
14
}
15
</script>
16
17
<p>请尝试向 body 元素添加属性,结果将是 true 而不是 false。</p>
18
19
<p><b>注释:</b>Internet Explorer 8 以及更早的版本不支持该方法。</p>
20
21
</body>
22
</html>
23