0
構建DIV在HTML創建是這樣的:構建DIV的通過‘的createElement’在JavaScript
<div id="parentdiv">
<div id="childdiv"></div>
</div>
我的代碼波紋管造成2個div但放在孩子的div旁邊父DIV,而不是在它裏面:
var pardiv = document.createElement('pardiv');
pardiv.setAttribute('id', "workspace");
pardiv.innerHTML = "Hello World";
pardiv.style.background = "red";
pardiv.width = 300;
pardiv.height = 300;
document.body.appendChild(pardiv);
var childdiv = document.createElement('childdiv');
childdiv.setAttribute('id', "childdiv");
childdiv.innerHTML = "Hello World";
childdiv.style.background = "yellow";
childdiv.width = 100;
childdiv.height = 100;
document.body.appendChild(childdiv);
如果程序員的結構div像HTML一樣通過JavaScript創建,它如何能像HTML一樣?