<html>
<head>
<meta http-equiv="Content-Type" content="text/html charset=UTF-8">
<title>拖动DIV</title>
<style type="text/css">
div{
width:200px
height:200px
background-color:#cef
position:absolute
}
</style>
<script type="text/javascript">
function movestart(obj) {
var width=event.offsetX
var height=event.offsetY
document.onmousemove=function() {
obj.style.left=event.clientX-width+"px"
obj.style.top=event.clientY-height+"px"
}
}
function moveend() {
document.onmousemove=null
}
</script>
</head>
<body>
<div id="mydv" onmousedown="movestart(this)" onmouseup="moveend()">这个可以拖动</div>
</body>
</html>