<div>a</div>
<div>a</div>
<div>a</div>显示的时候显示a0 a1 a2这样内容后加上div的序列号。 js咋整一下。请教。 

解决方案 »

  1.   

    给你个例子  试试把
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>Untitled Page</title>
        <script>
        var name=0
        function show()
        {   
        var x=Math.floor(Math.random()*1160);
        var y=Math.floor(Math.random()*800);
        var mp=document.getElementById("a");
        var s="<div style='height:100px; width:100px; border:2 px; background-color:Red; left:"+x.toString()+"px; top: "+y.toString()+"px; z-index:500; position:absolute' id=div"+name.toString()+"><input id=but"+name.toString()+" onclick=endit(div"+name.toString()+") type='button' value='关闭' />DIV_"+name.toString()+"郁闷啊^_^</div>";
        mp.insertAdjacentHTML("beforeEnd",s);
        name++;   
        }
        function endit(o)
        {
       var b=o.id;
       var mp=document.getElementById("a");
       mp.removeChild(o);    }
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div id="a">
            <input id="Button1" type="button" value="button" onclick="show()" />
        </div>
        </form>
    </body>
    </html>
      

  2.   

    <div>a</div> 
    <div>a</div> 
    <div>a</div>
    <script>
    var div=document.getElementsByTagName("div");
    for(var i=0;i<div.length;i++){ div[i].innerHTML+=i }
    </script>