假如我要创建一个DIV,我不想象以上所写的直接用HTML串起来生成,想用类似于 var div = document.createElement("div")这种方法来创建的话,要达到跟以上代码一样的效果,要怎么写?

解决方案 »

  1.   

    <body>
    <div id="div1"></div><script>
    function f1()
    {
    var div = document.createElement("div")
    var tmptb=document.createElement("table");
    var tmptr=document.createElement("tr");
    var tmptd=document.createElement("td");
    var tmpimg=document.createElement("img");
    var tempbody=document.createElement("tBody");
    tmptb.bgcolor="#ffffff'";
    tmptb.height='50' 
    tmptb.cellSpacing='0' 
    tmptb.cellPadding='0' 
    tmptb.width='200'
    tmptb.border='0'
    tmptd.innerText="sss";tmptd.width='23'div.style.position="absolute";
    var left=(screen.width*0.82-180)/2; 
    var top=(screen.height*0.82-50)/2;
    div.style.left=left;
    div.style.top=top;
    tmpimg.src='..\Images\indicator.gif';
    document.all.div1.appendChild(div);
    div.insertBefore(tmptb);
    tmptb.insertBefore(tempbody);
    tempbody.insertBefore(tmptr);
    tmptr.insertBefore(tmptd);
    tmptd.insertBefore(tmpimg)}
    f1();
    </script>
    </body>
      

  2.   

    多谢忘情火了,从你身上学到不少东西。
    这段代码假如直接写在页面,图片可以正常显示,但放在js文件,就显示一个X
      

  3.   


    <img src='..\Images\indicator.gif'>倒!应该这样写吧<src='../Images/indicator.gif'>