jquery table 鼠标选中单元格效果
来源:互联网 发布:尸者的帝国知乎 编辑:程序博客网 时间:2024/05/17 03:04
<html><head><title>jquery table 选中效果</title><script type="text/javascript" src="http://www.srcfans.com/js/jquery-1.9.1.min.js"></script><style>.tb{cellspacing:0px;border-spacing: 0px;border:1px solid #000;}.tb td{width:100px;height:50px;border:1px solid #000;}.td_bg{background:#FFAA00;}</style><script>var mouse_begin={x:0,y:0};var mouse_end={x:0,y:0};$(function(){init();$("body").mousedown(function(){$(".tb td").removeClass('td_bg');//点击表格之外的部分,清空所有选中})})function init(){mouseDown();mouseUp();}function mouseDown(){$(".tb td").mousedown(function(e){e.stopPropagation();//阻止继承父元素document的mousedown事件mouse_begin={x:$(this).parent().parent().find("tr").index($(this).parent()[0]),y:$(this).parent().find("td").index($(this)[0])};$(".tb td").removeClass('td_bg');//清空所有选中$(this).addClass('td_bg');mouseMove(); });}function mouseMove(){$(".tb td").mouseover(function(){ $(".tb td").removeClass('td_bg');//清空所有选中 mouse_end={x:$(this).parent().parent().find("tr").index($(this).parent()[0]),y:$(this).parent().find("td").index($(this)[0])}; var maxX=mouse_begin.x<mouse_end.x?mouse_end.x:mouse_begin.x; var minX=mouse_begin.x<mouse_end.x?mouse_begin.x:mouse_end.x; var maxY=mouse_begin.y<mouse_end.y?mouse_end.y:mouse_begin.y; var minY=mouse_begin.y<mouse_end.y?mouse_begin.y:mouse_end.y; for(var i=minX;i<=maxX;i++){for(var j=minY;j<=maxY;j++){$(".tb tr:eq("+i+") td:eq("+j+")").addClass('td_bg');} } //$(this).addClass('td_bg');});}function mouseUp(){$(".tb td").mouseup(function(){ $(".tb td").unbind('mouseover');});}</script></head><body><table id="tb" class="tb"><tr><td></td> <td></td> <td></td> <td></td></tr><tr><td></td> <td></td> <td></td> <td></td></tr><tr><td></td> <td></td> <td></td> <td></td></tr><tr><td></td> <td></td> <td></td> <td></td></tr></table></body></html>
阅读全文
1 0
- jquery table 鼠标选中单元格效果
- jquery table选中行颜色(效果更好)
- Jquery实现鼠标双击Table单元格变成文本框
- jquery table合并单元格
- jquery实现效果比较好的table选中行颜色
- jquery实现效果比较好的table选中行颜色
- 单元格的选中效果和辅助效果
- table合并单元格(Jquery 插件
- jquery table合并行单元格
- jquery合并table相同单元格
- jquery获取table指定单元格
- [HTML]table选中行效果
- jquery checkbox选中效果
- Jquery选中效果
- jQuery鼠标提示效果
- jquery鼠标经过效果
- JQuery鼠标跟随效果
- jquery 鼠标拖动效果
- Java常见面试题总结
- QQ第三方登录实现
- [DP][倍增NTT]LOJ#6059. 2017 山东一轮集训 Day1. Sum
- javaScript之数组去重
- 第一天的博客
- jquery table 鼠标选中单元格效果
- 自定义GridView添加头视图和足视图
- HTML 速查列表
- vtk处理外部事件
- 分布式框架简介SSM组合+ springmvc+mybatis+shiro+restful+bootstrap
- [bzoj3060]Tour de Byteotia
- windows下如何github ssh 公钥
- iOS端一次视频全屏需求的实现
- Spark源码之persist方法,cache方法以及StorageLevel