本帖最后由 abc54288 于 2010-03-14 17:50:35 编辑

解决方案 »

  1.   

    <script>
    var top=Math.round(Math.random()*(1000-100))+100;
    var left=Math.round(Math.random()*(600-200))+200;
    alert(top+":"+left);
    </script>
      

  2.   

    divid.style.top=xxx;
    divid.style.left=xxx;
      

  3.   

    <!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> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
    <title>test </title>
    <style>
    #test{
    width:100px;
    height:100px;
    border:1px solid red;
    }
    </style>
    </head> 
    <body>
    <div id="test"></div>
    </body> 
    </html>
    <script>
       var top = Math.round(Math.random()*(1000-100))+100 + "" + "px";    
       var left = Math.round(Math.random()*(600-200))+200+ "" + "px";
       document.getElementById("test").style.marginTop = top;
       document.getElementById("test").style.marginLeft = left;
    </script>
    这个比较完整
      

  4.   

    <div id="d">我是学习的……
    学无止境……
    </div>
    <script type="text/javascript">
    function pos(){
    var d=document.getElementById("d");
    d.style.left=Math.round((Math.random()*900)+100);
    d.style.top=Math.round((Math.random()*400)+200);
    setTimeout("pos()",500);
    }
    window.onload=pos;
    </script>
      

  5.   

    如果这个ID这是这样的形式,如<DIV onmousedown=getFocus(this) id=cc{content.id}>那JS中就不能直接指定某一个ID了,该如何办呢?
      

  6.   

    那你就用document.getElementByTagName吧 取出来再循环