DYNATEST.HTML:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<html>
<head>
<title> New Document </title>
<style type="text/css">
.text1
{
position: absolute;
display: none;
//visibility: none;
}
</style>
<script type="text/javascript">
<!--
function doit()
{
with(document.all.text1)
{
//alert(style.display.toUpperCase());
if(style.display.toUpperCase() == "NONE" || style.display.length == 0)
{
style.display = "inline";
style.left = 100;
style.top = 200;
value = "this is text1";
}
}
}function doit2()
{
var t; t = document.createElement("<input type=text name=text2 id=text2 value='this is text2'>");
document.body.appendChild(t);
t.style.left = 200;
t.style.top = 100;
t.style.backgroundColor = "silver";
}
//-->
</script>
</head><body bgcolor="#FFFFFF">
<input type=text name=text1 id=text1 class=text1>
<input type=button value="User CSS Attribute (IE 4)" onclick="doit()">
<input type=button value="createElement (IE 5)" onclick="doit2()">
</body>
</html>很简单,要求用 IE 4.0+ 浏览,在 IE 5.0+ 才可以动态的用 document.createElement;Netscape 中只能用非标准的 <LAYER> 来实现。

解决方案 »

  1.   

    docuemnt.write(strHTML)就可以了,strHTML为你要显示的文本矿以及它的一些属性,譬如ID号,颜色,值等,
    也可以用一些可以做Containner的标签,如<p>,<div>之类的
    举个例子:
    <p id="pTest"><p>
    然后在你想显示并控制它的函数中,
    设置pTest.innerHTML = strHTML即可。
    试试吧。
    Enjoy it! ;-)
      

  2.   

    动态元素生成,kechuangjian
    <SCRIPT>
    function fnCreate(){
    oData.innerHTML="";
    var oOption=oSel.options[oSel.selectedIndex];
    if(oOption.text!=""){
    var aElement=document.createElement(oOption.text);
    eval("aElement." + oOption.value + "='" + oText.value + "'");
    if(oOption.text=="A"){
    aElement.href="javascript:alert('A link.')";
    }
    oData.appendChild(aElement);
    }
    }
    </SCRIPT>