JS实现两表格里数据来回转移的方法

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>提货送货</title> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="this is my page"> <style type="text/css"> a{ text-decoration: none; text-align: center; } #main{ postion:relation; } /*左边层*/ #div1 { float: left; postion:relation; } #div1 #left{ float:left; } /*中间层*/ #div2{ float:left; margin-top:50px; } #div2 #div2_2{ margin-top:15px; } /*右边层*/ #div3 { float: left; } #tab_sendValue1 input,#tab_sendValue3 input{ width:40px; border:none; } </style> <script type="text/javascript"> //全选事件 function myclick(e,itemName){ var items = document.getElementsByName(itemName); for(var i = 0;i < items.length;i++){ items[i].checked = e.checked; } } //移动左边表格的值到右边表格 function sendValueToRight(){ var ary = new Array(); var items = document.getElementsByName("item"); for(var i = 0;i < items.length;i++){ if(items[i].checked){ ary[i] = document.getElementById("id"+items[i].value).parentNode.parentNode.rowIndex;//保存下所选行的索引 moveValueOfLeft(items[i].value);//移值 } } for(var i = ary.length;i >0;i--){ var leftTbody = document.getElementById("tab_sendValue1"); //左边表格的tbody //判断数组ary里的值是不是行索引 if(!isNaN(ary[i-1])){ leftTbody.deleteRow(ary[i-1]-1); //移除表格的所选行 } } document.getElementById("check_all").checked = false; //全选复选框置为false } //移动左边表格的值到右边表格 function moveValueOfLeft(op){ var wbid = document.getElementById("id"+op).value; var wbno = document.getElementById("no"+op).value; var destination = document.getElementById("des"+op).value; var status = document.getElementById("status"+op).value; var billingdate = document.getElementById("date"+op).value; var rightTbody = document.getElementById("tab_sendValue3"); //右边表格的tbody var tr = document.createElement("tr"); var td1 = document.createElement("td"); var td2 = document.createElement("td"); var td3 = document.createElement("td"); var td4 = document.createElement("td"); var td5 = document.createElement("td"); var td6 = document.createElement("td"); td1.innerHTML = "<input type='checkbox' value='"+wbid+"'>"; td2.innerHTML = "<input type='text' value='"+wbid+"'>"; td3.innerHTML = "<input type='text' value='"+wbno+"'>"; td4.innerHTML = "<input type='text' value='"+destination+"'>"; td5.innerHTML = "<input type='text' value='"+status+"'>"; td6.innerHTML = "<input type='text' value='"+billingdate+"'>"; tr.appendChild(td1); tr.appendChild(td2); tr.appendChild(td3); tr.appendChild(td4); tr.appendChild(td5); tr.appendChild(td6); rightTbody.appendChild(tr); } //移动右边表格的值到左边表格 function sendValueToLeft(){ var ary1 = new Array(); var items = document.getElementsByName("item1"); for(var i = 0;i < items.length;i++){ if(items[i].checked){ //先保存所选行的索引 在移除掉所选行 ary1[i] = document.getElementById("id"+items[i].value).parentNode.parentNode.rowIndex; //保存下所选行的索引 moveValueOfRight(items[i].value);//移值 } } for(var i = ary1.length;i >0;i--){ var rightTbody = document.getElementById("tab_sendValue3"); //右边表格的tbody //判断数组ary里的值是不是行索引 if(!isNaN(ary1[i-1])){ rightTbody.deleteRow(ary1[i-1]-1); //移除表格的所选行 } } document.getElementById("check_all3").checked = false; //全选复选框置为false } //移动右边表格的值到左边表格 function moveValueOfRight(op){ var wbid = document.getElementById("id"+op).value; var wbno = document.getElementById("no"+op).value; var destination = document.getElementById("des"+op).value; var status = document.getElementById("status"+op).value; var billingdate = document.getElementById("date"+op).value; var leftTbody = document.getElementById("tab_sendValue1"); //左边表格的tbody var tr = document.createElement("tr"); var td1 = document.createElement("td"); var td2 = document.createElement("td"); var td3 = document.createElement("td"); var td4 = document.createElement("td"); var td5 = document.createElement("td"); var td6 = document.createElement("td"); td1.innerHTML = "<input type='checkbox' value='"+wbid+"'>"; td2.innerHTML = "<input type='text' value='"+wbid+"'>"; td3.innerHTML = "<input type='text' value='"+wbno+"'>"; td4.innerHTML = "<input type='text' value='"+destination+"'>"; td5.innerHTML = "<input type='text' value='"+status+"'>"; td6.innerHTML = "<input type='text' value='"+billingdate+"'>"; tr.appendChild(td1); tr.appendChild(td2); tr.appendChild(td3); tr.appendChild(td4); tr.appendChild(td5); tr.appendChild(td6); leftTbody.appendChild(tr); } </script> </head> <body> <div> <div> <div > <div> <input type="button" value="查未配载单"/> <input type="button" value="筛选未配载" /> <input type="button" value="清除" /> <inputtype="button" value="还原" /> </div> <div>自营路线:<select><option>长沙</option></select></div> </div> <input type="button" value="未配载托运单"> <input type="button" value="已清除托运单"> <!-- 表格1 --> <div> <table> <thead> <tr> <th>全选<input type="checkbox"></th> <th>托运单号</th> <th>货号</th> <th>目的地</th> <th>状态</th> <th>托运日期</th> </tr> </thead> <tbody> <tr> <td><input type="checkbox" value="2"></td> <td><input type="text" value="2"></td> <td><input type="text" value="89757"></td> <td><input type="text" value="长沙"></td> <td><input type="text" value="在库"></td> <td><input type="text" value="ggyy"></td> </tr> <tr> <td><input type="checkbox" value="3"></td> <td><input type="text" value="3"></td> <td><input type="text" value="007"></td> <td><input type="text" value="长沙"></td> <td><input type="text" value="在库"></td> <td><input type="text" value="ggyy"></td> </tr> <tr> <td><input type="checkbox" value="4"></td> <td><input type="text" value="4"></td> <td><input type="text" value="008"></td> <td><input type="text" value="长沙"></td> <td><input type="text" value="在库"></td> <td><input type="text" value="ggyy"></td> </tr> <tr> <td><input type="checkbox" value="5"></td> <td><input type="text" value="5"></td> <td><input type="text" value="009"></td> <td><input type="text" value="长沙"></td> <td><input type="text" value="在库"></td> <td><input type="text" value="ggyy"></td> </tr> </tbody> </table> </div> </div> <form action="/logistic7.2/loadingSet/save.do" method="post"> <div> <div>当前网点<br> <select> <option>长沙</option> </select> </div> <div><input type="button" value=">>" /></div> <div><input type="button" value="<<" /></div> </div> <div> <div> <input type="button" value="查已配载单 " /> <input type="submit" value="保存配载单"/><br> 到货网点:<input type="text"><br> 车辆编号:<select> <option>-----请选择-----</option> </select> 到货时间:<input type="text"> </div> <!-- 表格3 --> <div> <table> <thead> <tr> <th>全选<input type="checkbox"></th> <th>托运单号</th> <th>货号</th> <th>目的地</th> <th>状态</th> <th>托运日期</th> </tr> </thead> <tbody> </tbody> </table> </div> </div> </form> </div> </body> </html>

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wgjydy.html