日期:2014-05-16  浏览次数:20346 次

appendChild你怎么了??
ie9 f12 返回的结果SCRIPT5007: Unable to get value of the property 'appendChild': object is null or undefined
<!DOCTYPE html>
<html>
<head><title></title><script type="text/javascript">
var para=document.createElement("p");
var test=document.getElementById("test");
var text=document.createTextNode('hello word!');
para.appendChild(text); 
test.appendChild(para);
</script></head>
<body>
<div id="test"></div>
</body>
</html>
ie9 firefox 都不能appendchild??那里错了?求解答

------解决方案--------------------
<!DOCTYPE html>
<html>
<head><title></title><script type="text/javascript">
window.onload=function(){
var para=document.createElement("p");
var test=document.getElementById("test");
var text=document.createTextNode('hello word!');
para.appendChild(text); 
test.appendChild(para);
}
</script></head>
<body>
<div id="test"></div>
</body>
</html>