<div id="placeholder"></div>
var placeholder=document.getElementById("placeholder");
var description="test";
placeholder.appendChild(description);,为什么第二行代码就是不生效。求解!
var placeholder=document.getElementById("placeholder");
var description="test";
placeholder.appendChild(description);,为什么第二行代码就是不生效。求解!
<html>
<head>
<meta charset="gbk" />
<title></title>
</head>
<body>
<div id="placeholder"></div>
<script type="text/javascript">
var placeholder = document.getElementById("placeholder");
var description = "test";
placeholder.innerHTML = description;
// 或者
var textNode = document.createTextNode('test123');
placeholder.appendChild( textNode )
</script>
</body>
</html>
var placeholder=document.getElementById("placeholder");
var description=document.createTextNode('test');
placeholder.appendChild(description);方法二:
var placeholder=document.getElementById("placeholder");
var description="test";
placeholder.innerHTML=description;
http://www.w3school.com.cn/js/index.asp再看下
html dom
DHTML
var description=document.createTextNode('test');
placeholder.appendChild(description);var placeholder=document.getElementById("placeholder");
var description="test";
placeholder.innerHTML=description;
确实,'test'是javascript的变量,但它并不属于dom范畴,而appendChild()这个方法是隶属于dom的,所以单纯的appendChild('test')并没有意义,不过我也挺奇怪,为什么不报错捏?求高手解释m(_)m