帮助中心
获取牛币
联系我们
关于我们
版权声明
素材牛首页
微博登录
QQ登录
微信扫码登录
注册
登录
新浪微博
QQ登陆
微信登录
热门搜索:
小程序
支付
Java
后台模板
上传
商城模板
jQuery
手机
Thinkphp
微信
Vue.js
首 页
网页特效
整站源码
PHP实例
网站模版
工具箱
常用代码
论坛
游戏源码
资源分享
当前位置:
首页
»
精选常用代码
» 表格拖选选中功能
表格拖选选中功能
浏览:1070次
-
评论:1次
-
发布时间:2017-12-07
Html
Css
Js
会议室名称
10:00
11:00
12:00
13:00
14:00
15:00
16:00
17:00
18:00
19:00
会议室1
会议室2
.hidden { display:none; } table td.dselected { background-color:green; }
$(function() { var now = new Date(); var year = now.getFullYear(); var month = now.getMonth() + 1; var day = now.getDate(); $('.busy').click(function() { location.href = $(this).data('href'); }); // 可 $('.mavailab').click(function() { }); $('body').append('
'); var table = $("#meetingRoomsTable"); $('#meetingRoomsTable .mavailab').hover(function() { $('#am-popover-order .am-popover-inner').text('双击或拖动选择' + $(this).data('time') + $(this).parent().data('room-name')); var thisOffsetLeft = $(this).offset().left; var popoverWidth = $('#am-popover-order').outerWidth(); var offsetLeft = thisOffsetLeft + (popoverWidth / 2 - $(this).outerWidth() / 2 + 10) > $('body').width() - 20 ? $('body').width() - popoverWidth - 5 : thisOffsetLeft - popoverWidth / 2 + $(this).outerWidth() / 2 $('#am-popover-order').css({ left: offsetLeft, top: $(this).offset().top - 52 }) $('#am-popover-order').show(); }, function() { $('#am-popover-order').hide(); }); $('.mlimit').each(function() { $(this).style = "background=red"; $(this).popover({ content: '受限', trigger: 'hover' }); }); // 时间选择 var isMouseDown = false; var startRowIndex = null; var startCellIndex = null; var startCellTime = null; var endCellTime = null; var cellRoomId = null; var cellRoomName = null; function selectTo(cell) { var row = cell.parent(); var cellIndex = cell.index(); var rowIndex = row.index(); var rowStart, rowEnd, cellStart, cellEnd; rowStart = startRowIndex; rowEnd = rowIndex; if (cellIndex < startCellIndex) { cellStart = cellIndex; cellEnd = startCellIndex; } else { cellStart = startCellIndex; cellEnd = cellIndex; } endCellTime = cell.data('time'); cellRoomId = cell.parent().data('room-id'); cellRoomName = cell.parent().data('room-name'); var rowCells = table.find("tr").eq(rowStart).find("td"); for (var j = cellStart; j <= cellEnd; j++) { rowCells.eq(j).addClass("dselected"); } } table.find("td.meeting-cell").mousedown(function(e) { isMouseDown = true; var cell = $(this); table.find(".dselected").removeClass("dselected"); // deselect everything if (e.shiftKey) { selectTo(cell); } else { cell.addClass("dselected"); startCellIndex = cell.index(); startRowIndex = cell.parent().index(); startCellTime = cell.data('time'); endCellTime = cell.data('time'); } return false; // prevent text selection }) .mouseover(function() { if (!isMouseDown) return; selectTo($(this)); }) .bind("selectstart", function() { return false; }); $(document).mouseup(function() { if (isMouseDown) { // 检查选择的时间段 var dStart = new Date(year + '-' + month + '-' + day + 'T' + startCellTime + ':00'); var dEnd = new Date(year + '-' + month + '-' + day + 'T' + endCellTime + ':00'); var duration = (dEnd.getTime() - dStart.getTime()) / 60000 + 30; if (duration > 720) { duration = 60; } if (startCellTime == undefined) { isMouseDown = false; return; } if (cellRoomName == undefined) { isMouseDown = false; return; } alert(cellRoomName + "~~" + startCellTime + '&duration=' + duration); // 弹框选择会议类型 // TODO: 不存在, 改js /* $('#dlg-new-meeting-title').html('预订2017-11-30' + cellRoomName + startCellTime); $('#dlg-new-meeting-link-s').attr('href', '/meetings/d/2017-11-30/r/' + cellRoomId + '/new?startTime=' + startCellTime + '&duration=' + duration); $('#dlg-new-meeting-link-i').attr('href', '/meetings/d/2017-11-30/r/' + cellRoomId + '/new-interview?startTime=' + startCellTime + '&duration=' + duration); $('#dlg-new-meeting-link-c').attr('href', '/meetings/d/2017-11-30/r/' + cellRoomId + '/new-customer?startTime=' + startCellTime + '&duration=' + duration); */ // $('#new-meeting-dlg').modal({width: "280px"}); } isMouseDown = false; }); });
↑上面代码改变,会自动显示代码结果
jQuery调用版本:
2.1.4
<!doctype html><html><head><meta charset="utf-8"><title>表格拖选选中功能-www.sucainiu.com</title><script src="https://libs.baidu.com/jquery/2.1.4/jquery.min.js"></script><style>
</style></head><body>
<script>
</script>
</body></html>
立即下载
收藏
积分说明:注册即送10牛币,每日签到可获得5牛币,成为VIP会员可永久免牛币下载!
充值积分
充值会员
更多说明»
代码描述:jquery表格拖选功能
实现表格拖选时间段,能够添加任务,工作等
多图一次上传预览效果
vue抽奖弹框
讨论这个常用代码(1)
回答他人问题或分享心得会奖励牛币
Lv10 CTO
华***n
2017年12月11日
感谢作者分享~
回复
文明上网,理性发言! 😉 阿里云幸运券,
戳我领取
发表评论
提交回复
我的积分余额:
0
已下载次数:
1070
所需牛币:
5
开始下载
牛币获取:
签到、评论、充值
» 在线充值
(10牛币=1元)
成为VIP可永久免积分下载全部常用代码
» 查看详情
VIP
客服
签到
充值