随笔 - 97  文章 - 20  评论 - 94  阅读 - 22万

JS-表的行添加操作(insertRow)

var rowCount = document.getElementById("dataTable").rows.length;
 

   var createCount;
    var tbObj = document.getElementById("dataTable");
    if(rowCount == 0){
     var rs = tbObj.rows;
     var count = rs.length;
     document.mainFrm.rowNewCount.value = 0;
     document.mainFrm.rowCount.value = 0;
     var newTr = tbObj.insertRow();
               
     newTr.height="22";
     //newTr.style="cursor:'hand'";
     newTr.onMouseMove="style.backgroundColor='#EFEFEF'";
     newTr.onMouseOut="style.backgroundColor='#ffffff'";
    
     var newTd0 = newTr.insertCell();
     newTd0.width="3%";
     newTd0.align="center";
    
     var newTd1 = newTr.insertCell();
     newTd1.width="40%";
     newTd1.align="left";
    
     var newTd2 = newTr.insertCell();
     newTd2.width="40%";
     newTd2.align="left";
    
     newTd0.innerHTML = "<input type='checkbox' name='relationId' id='relationId' value=''>";
     newTd1.innerHTML = "<input type='text' name='orgCode' value='' class='noemptyInput' style='width: 100%' onblur='ajaxValidateCode(this)'>";
     newTd2.innerHTML = "<input type='text' name='orgName' value='' class='noemptyInput' style='width: 100%'>";
     createCount = count;
     createCount ++;
     document.mainFrm.createCount.value = createCount;
    } else {
     var rs = tbObj.rows;
     var count = rs.length;
     var row0 = rs[count - 1];
     var newRow = row0.cloneNode(true);
     newRow.firstChild.nextSibling.firstChild.value = "";
     newRow.lastChild.firstChild.value = "";
     if(document.mainFrm.rowCount.value == ""){
      document.mainFrm.rowCount.value = count;
     }
     createCount = count;
     createCount ++;
     document.mainFrm.createCount.value = createCount;
     row0.appendChild(newRow);
    }

posted on   关寒融冰  阅读(6656)  评论(0编辑  收藏  举报
编辑推荐:
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
< 2009年5月 >
26 27 28 29 30 1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31 1 2 3 4 5 6

鲁ICP备07018066号-1
点击右上角即可分享
微信分享提示