<!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=gb2312" />
<title>javascript定位</title><script type="text/javascript">
function change(left,top){
var objChange=document.getElementById("div1");
objChange.style.left=left;
objChange.style.top=top;
}
</script><style type="text/css">
.div1{
background-color:#999999;
border:dotted;height:70px;
width:400px;
}
</style>
</head>
<body><div class="div1" style=" overflow:auto;" id="div1">
Play the video on the original site.
When the play begins then the NetVideoHunter captures the videolink and you can see it in the list at the left side of this window.
You can Download videos if you click on the "Download" button in the list or you can preview it with the "Play" button to be sure you downloading the right videoPlay the video on the original site.
When the play begins then the NetVideoHunter captures the videolink and you can see it in the list at the left side of this window.
You can Download videos if you click on the "Download" button in the list or you can preview it with the "Play" button to be sure you downloading the right video
</div>
<br/>
<hr/>
<input type="button" value="移动到(100,100)" onclick="change(100,100)" />
<input type="button" value="移动到(50,50)" onclick="change(50,50)" />
<input type="button" value="移动到(200,200)"  onclick="change(200,200)"/>
<input type="button" value="移动到(0,80)" onclick="change(0,80)" />
</body>
</html>

解决方案 »

  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>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>javascript定位</title><script type="text/javascript">
    function change(left,top){
    var objChange=document.getElementById("div1");
    objChange.style.left=left+'px';
    objChange.style.top=top+'px';
    }
    </script><style type="text/css">
    .div1{
    background-color:#999999;
    border:dotted;height:70px;
    width:400px;
    }
    </style>
    </head>
    <body><div class="div1" style=" overflow:auto; position:absolute;" id="div1">
    Play the video on the original site.
    When the play begins then the NetVideoHunter captures the videolink and you can see it in the list at the left side of this window.
    You can Download videos if you click on the "Download" button in the list or you can preview it with the "Play" button to be sure you downloading the right videoPlay the video on the original site.
    When the play begins then the NetVideoHunter captures the videolink and you can see it in the list at the left side of this window.
    You can Download videos if you click on the "Download" button in the list or you can preview it with the "Play" button to be sure you downloading the right video
    </div>
    <br/>
    <br/>
    <br/>
    <br/>
    <br/>
    <br/>
    <hr/>
    <input type="button" value="移动到(100,100)" onclick="change(100,100)" />
    <input type="button" value="移动到(50,50)" onclick="change(50,50)" />
    <input type="button" value="移动到(200,200)" onclick="change(200,200)"/>
    <input type="button" value="移动到(0,80)" onclick="change(0,80)" />
    </body>
    </html>要把.div1加上绝对定位position:absolute;然后
    objChange.style.left=left+'px';
    objChange.style.top=top+'px';js代码left 跟 top值 要加上'px'
      

  2.   

    为啥 还要设置position? 我设成relative也对 这是为啥
      

  3.   


    只有层在飘起来的时候(也就是浮动position:absolute,我一般这样叫), 才可以控制这个层得 top 和 left 
      

  4.   

    还是不太懂...能在说明白点么? 就是有关position的问题
      

  5.   


    position:absolute
    是绝对定位,如果使用这个样式,那么该元素就脱离了文档流。这样就可以用left,跟top属性,来定位该元素的位置