为什么我无法得到这个标签的节点名?
document.write(document.getElementById("button").nodeName);
这里button元素写到<script>下面去了,页面加载顺序从上到下,因此加载到js的时候,无法找到button元素;
将<button>放到<script>上面去
<body>
<div id="content">
<h1>html</h1>
<h1>php</h1>
<h1>javascript</h1>
<h1>jquery</h1>
<h1>java</h1>
</div>
<script type="text/javascript">
function clearText() {
var content=document.getElementById("content");
while(content.firstChild!=null){
content.removeChild(content.firstChild);
}
alert(" 已经全部清除 ");
}
document.write(document.getElementById("button").nodeName);
document.write(555);
</script>
<button id="button" onclick="clearText()">清除节点内容</button>
</body>
</html>代码没问题啊,body里怎么写的呢
我已经在代码里给button加了id="button"了