87,955
社区成员
![](https://csdnimg.cn/release/cmsfe/public/img/topic.427195d5.png)
![](https://csdnimg.cn/release/cmsfe/public/img/me.40a70ab0.png)
![](https://csdnimg.cn/release/cmsfe/public/img/task.87b52881.png)
![](https://csdnimg.cn/release/cmsfe/public/img/share-circle.3e0b7822.png)
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Sample</title>
<style type="text/css">
body div {background:#ABE;width:70px;position:absolute;filter:alpha(style=0,opacity=50)}
table {background:#DDD;border:1px;}
table tr td {width:70px;border:1px;}
</style>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
$(document).ready(function(){
var obj;
var selIndex=-1;
var l=0;t=0;
$("div").mousedown(function(e){
obj=this;
sx=e.pageX+document.body.scrollLeft;
sy=e.pageY+document.body.scrollTop;
});
$("div").mouseup(function(e){
obj=null;
});
$("div").mousemove(function(e){
if(obj){
ex=e.pageX+document.body.scrollLeft;
ey=e.pageY+document.body.scrollTop
l=(ex-sx+$(this).offset().left);
t=(ey-sy+$(this).offset().top );
$(this).css("left",l+"px");
$(this).css("top" ,t+"px");
sx=ex;sy=ey;
$("td").css("background","#DDD");
$("td").each(function(){
if($(this).offset().left<=l
&& $(this).offset().top <=t){
selIndex=$("td").index(this);
}
});
$("td:eq("+selIndex+")").css("background","#FFF");
}
});
});
</script>
</head>
<body><div></div>
<table>
<tr><td>1</td><td>11</td></tr>
<tr><td>2</td><td>22</td></tr>
<tr><td>3</td><td>33</td></tr>
<tr><td>4</td><td>44</td></tr>
</table>
</body>
</html>