<SCRIPT LANGUAGE="JavaScript">
function MakeDiv(divID)
{
var divObj = document.getElementById(divID); var box = document.createElement("div");
box.style.backgroundColor= divObj.style.backgroundColor; //背景相同
box.style.width = divObj.scrollWidth+"px"; //宽度相同
box.style.height = divObj.scrollHeight+"px"; //高度相同
//如何设置左边距也相同呢?
box.style.marginLeft = divObj.style.marginLeft; box.style.overflow = "hidden"; document.body.appendChild(box);
}
</SCRIPT>
<div id="div1" style="background-color:silver;" />d</div><div id="div2" style="background-color:green;margin-left:20px;" />d</div><input type="button" onclick="MakeDiv('div1')" value="创建DIV1" /><input type="button" onclick="MakeDiv('div2')" value="创建DIV2" />
asdasdasdasd