//注释:获取对象.示例:$("objectId") 等同于 document.getElementById("objectId") if (typeof $ != "function") { var $ = function (ids) { return document.getElementById(ids) }; } //注释:获取坐标,parentNode最后节点.示例:absPos(object).x function absPos(_node, parentNode) { var x = y = 0; var node = _node; do { if (parentNode && node == parentNode) { break; } x += node.offsetLeft; y += node.offsetTop; } while (node = node.offsetParent); node = _node; return { 'x': x, 'y': y }; } function addEvent(object, event, func) { if (object.addEventListener) { /* W3C方法(DOM方法)下面语句中的false意思是用于冒泡阶段,若是true则是用于捕获阶段(IE不支持捕获),所以这里用false是一方面的原因是为了统一 */object.addEventListener(event, func, false); return true; } else if (object.attachEvent) { /* MSIE方法(IE方法) */object['e' + event + func] = func; object[event + func] = function () { object['e' + event + func](window.event); }; object.attachEvent('on' + event, object[event + func]); return true; } /*如两种方法都不具备则返回false */return false; } //注释:判断是否是对象内子节点触发的onmouseover和onmouseout.示例:e = e || event;if (isMouseLeaveOrEnter(e, obj)) {} function isMouseLeaveOrEnter(e, handler) { if (e.type != 'mouseout' && e.type != 'mouseover') return false; var reltg = e.relatedTarget ? e.relatedTarget : e.type == 'mouseout' ? e.toElement : e.fromElement; while (reltg && reltg != handler) reltg = reltg.parentNode; return (reltg != handler); }
var table = $("mainTable"); var tabEditDiv; //覆盖在table上的DIV var cellHide = [];//补充的rowspan,cellspan的格子 var moveMode = "";//鼠标移动模式 var moveArgs = []; //移动模式参数
addEvent(document,"mousemove",function(e){ e = e || window.event; if(moveMode == "cellWidth"){ //调整宽度
var temp = moveArgs[0]; var test = ""; for(var i=0;i var index = temp; for(var j=0;j if(i==cellHide[j][0] && temp>=cellHide[j][1]){index--;} } if(!table.rows[i].cells[index] || index 1){continue;} if(e.clientX > absPos(table.rows[i].cells[index]).x) table.rows[i].cells[index].style.width = e.clientX - absPos(table.rows[i].cells[index]).x + "px"; } loadTableEdit(); }else if(moveMode == "cellHeight"){ //调整高度 var index = moveArgs[0]; for(var i=0;i if(table.rows[index].cells[i].rowSpan > 1){continue;} if(e.clientY > absPos(table.rows[index].cells[i]).y) table.rows[index].cells[i].style.height = e.clientY - absPos(table.rows[index].cells[i]).y + "px"; } loadTableEdit(); } }); addEvent(document,"mouseup",function(e){ moveMode = ""; moveArgs = []; }); addEvent(document,"mouseout",function(e){ e = e || event; if (!isMouseLeaveOrEnter(e, this)) { return; } moveMode = ""; moveArgs = []; });
Kenyataan:
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn