<!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>
<style>
#div1 {width:100px; height:100px; background:red; position:absolute;}
</style>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script>
window.onload=function ()
{
var oDiv=document.getElementById('div1');
oDiv.onmousedown=function (ev)
{
var oEvent=ev||event;
var disX=oEvent.clientX-oDiv.offsetLeft;
var disY=oEvent.clientY-oDiv.offsetTop;
if(oDiv.setCapture)
{
oDiv.onmousemove=function (ev)
{
var oEvent=ev||event;
oDiv.style.left=oEvent.clientX-disX+'px';
oDiv.style.top=oEvent.clientY-disY+'px';
};
oDiv.onmouseup=function ()
{
oDiv.onmousemove=null;
oDiv.onmouseup=null;
oDiv.releaseCapture();
};
oDiv.setCapture();
}
else
{
document.onmousemove=function (ev)
{
var oEvent=ev||event;
oDiv.style.left=oEvent.clientX-disX+'px';
oDiv.style.top=oEvent.clientY-disY+'px';
};
document.onmouseup=function ()
{
document.onmousemove=null;
document.onmouseup=null;
};
}
return false;
};
};
</script>
</head><body>
asdfas
<div id="div1">
asdfs
</div>
zcvx
</body>
</html>问下这个是 拖拽的问题 。 if里的代码是在IE下拖拽时 不会选中div外面的文字 else里的是 在火狐下拖拽div时 不会选中 div外面的文字 去这个bug 是因为return false。 但是为什么写在else外面才好使 。不是应该放在else里面吗 放到里面反而不好使了这是为什么啊 ?
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<style>
#div1 {width:100px; height:100px; background:red; position:absolute;}
</style>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script>
window.onload=function ()
{
var oDiv=document.getElementById('div1');
oDiv.onmousedown=function (ev)
{
var oEvent=ev||event;
var disX=oEvent.clientX-oDiv.offsetLeft;
var disY=oEvent.clientY-oDiv.offsetTop;
if(oDiv.setCapture)
{
oDiv.onmousemove=function (ev)
{
var oEvent=ev||event;
oDiv.style.left=oEvent.clientX-disX+'px';
oDiv.style.top=oEvent.clientY-disY+'px';
};
oDiv.onmouseup=function ()
{
oDiv.onmousemove=null;
oDiv.onmouseup=null;
oDiv.releaseCapture();
};
oDiv.setCapture();
}
else
{
document.onmousemove=function (ev)
{
var oEvent=ev||event;
oDiv.style.left=oEvent.clientX-disX+'px';
oDiv.style.top=oEvent.clientY-disY+'px';
};
document.onmouseup=function ()
{
document.onmousemove=null;
document.onmouseup=null;
};
}
return false;
};
};
</script>
</head><body>
asdfas
<div id="div1">
asdfs
</div>
zcvx
</body>
</html>问下这个是 拖拽的问题 。 if里的代码是在IE下拖拽时 不会选中div外面的文字 else里的是 在火狐下拖拽div时 不会选中 div外面的文字 去这个bug 是因为return false。 但是为什么写在else外面才好使 。不是应该放在else里面吗 放到里面反而不好使了这是为什么啊 ?
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货