<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="Generator" content="EditPlus®">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<script src="jquery.min.js" type="text/javascript"></script>
<title>Document</title>
<style>
.d1{width:100px;height:100px;background:red;}
.d2{width:100px;height:100px;background:blue;}
</style>
</head>
<body>
<div class="d1">hello</div>
<div class="d2">world</div>
</body>
<script>
$('.d1').on('mousedown',function(){
var e = window.event||arguments[0];
var posx = $('.d2').offset().left;
var posY = $('.d2').offset().top;
$(document).bind('mousemove',function(){
var e = window.event||arguments[0];
var npx = e.clientX - posx;
var npy = e.clientY - posY;
$('.d2').css({'top':(npy +'px'),'left':(npx +'px'),'position':'absolute'})
})
$(document).bind('mouseup',function(){
$('document').unbind('mousemove');
$('document').unbind('mouseup');
})
})
</script>
</html>
$(document).unbind('mousemove');
$(document).unbind('mouseup');
document不要用引号