上msdn逛了逛,写了一个小程序,保存下来没准将来用的上
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>拖动</title>
<style>
.oDiv{}{
position:absolute;
top:1px;
left:1px;
height:50px;
width:50px;
border:1px solid #000000;
background-color:#eeeeee;
}
</style>
<script>
var xx=0,yy=0;
function saveXY(){
xx=event.clientX;
yy=event.clientY;
}
function moveXY(){
var obj=event.srcElement;
var x1=event.clientX;
var y1=event.clientY;
var t1=parseInt(obj.offsetTop);
var t2=parseInt(obj.offsetLeft);
obj.style.top=t1+(y1-yy);
obj.style.left=t2+(x1-xx);
}
</script>
</head>
<body ondragstart="saveXY()" ondragend="moveXY()">
<div contentEditable=true><div class="oDiv" onKeyDown="event.returnValue=0x0;this.blur();" onresizestart="this.parentElement.contentEditable=false;this.parentElement.contentEditable=true"></div></div>
</body>
</html>
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>拖动</title>
<style>
.oDiv{}{
position:absolute;
top:1px;
left:1px;
height:50px;
width:50px;
border:1px solid #000000;
background-color:#eeeeee;
}
</style>
<script>
var xx=0,yy=0;
function saveXY(){
xx=event.clientX;
yy=event.clientY;
}
function moveXY(){
var obj=event.srcElement;
var x1=event.clientX;
var y1=event.clientY;
var t1=parseInt(obj.offsetTop);
var t2=parseInt(obj.offsetLeft);
obj.style.top=t1+(y1-yy);
obj.style.left=t2+(x1-xx);
}
</script>
</head>
<body ondragstart="saveXY()" ondragend="moveXY()">
<div contentEditable=true><div class="oDiv" onKeyDown="event.returnValue=0x0;this.blur();" onresizestart="this.parentElement.contentEditable=false;this.parentElement.contentEditable=true"></div></div>
</body>
</html>