//////////////////////////////////////////处理页面操作/////////////////////////////////////// //复制所选 function copySelect(){ var checkboxs = document.getElementsByName("checkbox"); for (var i=0; i<checkboxs.length; i++) { if(checkboxs[i].checked == true){ checkboxs[i].checked = false; copyTr(checkboxs[i]); checkboxs[i].checked = true; } } }
function copyTr(obj) { var tbody = document.getElementById("tbData").getElementsByTagName("tbody")[0]; var Str = obj.parentNode.parentNode; var tr = Str.cloneNode(true); tbody.appendChild(tr); }
//删除所选 function delSelect(){ var checkboxs = document.getElementsByName("checkbox"); var table = document.getElementById("tbData"); var tr = table.getElementsByTagName("tr"); for (var i=0; i<checkboxs.length; i++) { if(tr.length==2){ checkboxs[i].checked = false; return; } if(checkboxs[i].checked==true){ removeTr(checkboxs[i]); i=-1; } } }
function removeTr(obj) { var sTr = obj.parentNode.parentNode; sTr.parentNode.removeChild(sTr); }
//全选按钮 function selectAll() { var checkboxs = document.getElementsByName("checkbox"); var mark = true; for (var i=0; i<checkboxs.length; i++) { if (checkboxs[i].checked==false){mark = false} } if (mark){ for (var i=0; i<checkboxs.length; i++) { checkboxs[i].checked = false; } }else{ for (var i=0; i<checkboxs.length; i++) { checkboxs[i].checked = true; } } }
//////////////////////////////////////////处理键盘操作/////////////////////////////////////// //键盘事件 function beginListen(){ if(document.addEventListener){ document.addEventListener("keydown",keyDown,true); }else{ document.attachEvent("onkeydown",keyDown); } } function stopListen(){ document.detachEvent("onkeydown",keyDown); }
//处理键盘事件 function keyDown(event){ if(event.keyCode==13){addTr()} if(event.keyCode==46){delTr()} }
//增加表格 function addTr() { var tbody = document.getElementById("tbData").getElementsByTagName("tbody")[0]; var sTr = tbody.getElementsByTagName("tr")[0]; var tr = sTr.cloneNode(true); tbody.appendChild(tr); }
//增加表格 function addTr() { var tbody = document.getElementById("tbData").getElementsByTagName("tbody")[0]; var trs = tbody.getElementsByTagName("tr"); var sTr = trs[trs.length-1]; var tr = sTr.cloneNode(true); tbody.appendChild(tr); }
//删除表格 function delTr() { var table = document.getElementById("tbData"); var tr = table.getElementsByTagName("tr"); if(tr.length==2){return;} var lastTr = tr[tr.length-1]; lastTr.parentNode.removeChild(lastTr); }
//////////////////////////////////////////处理按钮事件/////////////////////////////////////// //自动填充 var currentObj; function showDiv(event,obj) { var eX = event.clientX; var eY = event.clientY; var sY = document.body.parentNode.scrollTop; var dY = eY + sY; var divShowInput = document.getElementById("divShowInput"); divShowInput.style.top = dY + "px"; divShowInput.style.left = eX+"px"; divShowInput.style.display = "block"; currentObj = obj; ////智能菜单//// fixMenu(); //判断焦点位置 var tds = obj.parentNode.parentNode.getElementsByTagName("td"); var tdOrder; for (var i = 0; i < tds.length; i++ ){ if(tds[i] === obj.parentNode){ tdOrder = i; } } //填充标题标题 var tdTitleTr = document.getElementById("tbData").getElementsByTagName("tr")[0]; var tdTitle = tdTitleTr.getElementsByTagName("td")[tdOrder]; document.getElementById("barTitle").innerHTML = tdTitle.innerHTML; //收集表格信息//判断重复 var trs = obj.parentNode.parentNode.parentNode.getElementsByTagName("tr"); var autoFillP = document.getElementById("autoFillP"); var bankM = true; for (var i = 0; i < trs.length; i++ ){ var inputValue = trs[i].getElementsByTagName("td")[tdOrder].getElementsByTagName("input")[0].value; if (inputValue != "") { bankM = false; var menus = autoFillP.getElementsByTagName("a"); if(menus.length > 0) { var beliveM = true; for (var j = 0; j < menus.length; j++ ){ if(menus[j].firstChild.nodeValue == inputValue) { beliveM = false; } } if(beliveM){ var Svalue = document.createElement("a"); Svalue.setAttribute("href","javascript:void 0"); Svalue.onclick = function () {fillInput(this)}; var Stext = document.createTextNode(inputValue); Svalue.appendChild(Stext); autoFillP.appendChild(Svalue); } }else{ var Svalue = document.createElement("a"); Svalue.setAttribute("href","javascript:void 0"); Svalue.onclick = function () {fillInput(this)}; var Stext = document.createTextNode(inputValue); Svalue.appendChild(Stext); autoFillP.appendChild(Svalue); } } } if(bankM) { var Svalue = document.createElement("a"); Svalue.setAttribute("href","javascript:void 0"); var Stext = document.createTextNode("数据空"); Svalue.appendChild(Stext); autoFillP.appendChild(Svalue); } }
function fillInput(obj) { currentObj.value = obj.innerHTML; var divShowInput = document.getElementById("divShowInput"); divShowInput.style.display = "none"; }
function clearInput() { currentObj.value = ""; var divShowInput = document.getElementById("divShowInput"); divShowInput.style.display = "none"; }
function hideDiv(obj) { obj.parentNode.style.display = "none"; }
//删除智能菜单已有数据 function fixMenu() { var autoFillP = document.getElementById("autoFillP"); var values = autoFillP.getElementsByTagName("a"); for (var i = values.length-1; i >= 0; i-- ){ autoFillP.removeChild(values[i]); } } //////////////////////////////////////////处理按钮事件///////////////////////////////////////
//////////////////////////////////////////数据发送/////////////////////////////////////// function sendData() { var sendName = new Array("ok","A1","A2","A3","A4","A5","A6","A7","A8","A9","A10","A11"); var trs = document.getElementById("tbData").getElementsByTagName("tbody")[0].getElementsByTagName("tr"); for (var i = 0; i < trs.length; i++) { var sendValue = new Array(); var values = trs[i].getElementsByTagName("input"); var postString = sendName[1] + "=" + values[1].value;; for (var j = 2; j < values.length; j++) { postString = postString + "&" + sendName[j] + "=" + values[j].value; } var SendAjax = new Ajax("isave.asp",0,postString,sendok); SendAjax.post(); function sendok(revData){ alert(revData); } } }