如何动态设置div显示值

时间:2011-06-23 06:17:12

标签: javascript html

如何通过javascript动态显示div?

这是我的代码

var div = document.createElement("div");

var sBody = "<span style='background-color:#ffffc4;border:2px solid black;height:100%;width:100%;'>";

if (sLabel) {
    sBody += "<span style='font:10pt arial;font-weight:bold;padding-left:2px;text-align:center;width:100%;'>" + sLabel + "</span>";
}

sBody += "</span>";

div.innerHTML = sBody;
div.style.width = = iW;
div.style.height = iH;
div.style.display = 'inline';

1 个答案:

答案 0 :(得分:1)

将ur div添加到ur表单中...例如,你可以有一个id =“form1”的表单(或任何元素),并将你的新div附加到这个。

var form = document.getElementById("form1");
form.appendChild(div);