可拖动div出错

来源:百度知道 编辑:UC知道 时间:2024/06/09 11:48:30
这个是可拖动div的代码。
var offset_x;
var offset_y;
function Milan_StartMove(oEvent)
{
var whichButton;
if(document.all&&oEvent.button==1) whichButton=true;
else { if(oEvent.button==0)whichButton=true;}
if(whichButton)
{
var oDiv=document.getElementById("oDiv");
offset_x=parseInt(oEvent.clientX-oDiv.offsetLeft);
offset_y=parseInt(oEvent.clientY-oDiv.offsetTop);
document.documentElement.onmousemove=function(mEvent)
{
var eEvent;
if(document.all) eEvent=event;
else{eEvent=mEvent;}
var oDiv=document.getElementById("oDiv");
var x=eEvent.clientX-offset_x;
var y=eEvent.clientY-offset_y;

我把你的代码拷下来试了。没有问题啊。加了runat="server"一样的可以运行啊。见一你在拖动之前Milan_StartMove()加上这个
//清除选择
window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
清除一下选择。
或者看看你页面引用的dtd有问题没有

只有一点你要注意,有时是自定义的话,你看看运行出来后ID是否还是oDiv,你看看运行后的源代码就可以了。有的可能是:
top_oDiv