js-表格(table)添加列、删除列_第1页
js-表格(table)添加列、删除列_第2页
js-表格(table)添加列、删除列_第3页
js-表格(table)添加列、删除列_第4页
js-表格(table)添加列、删除列_第5页
已阅读5页,还剩3页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、js-表格(table)添加列、删除列功能图片截图如下:一、Js代码如下:?<script language="javascript" type="text/javascript">           function findObj(theObj, theDoc)             var p, i, foundOb

2、j;             if (!theDoc) theDoc = document;             if (p = theObj.indexOf("?") > 0 && parent.frames.length)        &

3、#160;        theDoc = parent.framestheObj.substring(p + 1).document; theObj = theObj.substring(0, p);                          if (!(foundOb

4、j = theDoctheObj) && theDoc.all)                 foundObj = theDoc.alltheObj; for (i = 0; !foundObj && i < theDoc.forms.length; i+) foundObj = theDoc.formsitheObj; for (i = 0; !foundObj && theD

5、oc.layers && i < theDoc.layers.length; i+) foundObj = findObj(theObj, theDoc.layersi.document);             if (!foundObj && document.getElementById)             

6、;    foundObj = document.getElementById(theObj); return foundObj;                    /添加一个列         count = 1;       

7、60; function AddNewColumn()             var txtTDLastIndex = findObj("txtTDLastIndex", document);             var columnID = parseInt(txtTDLastIndex.value);  &#

8、160;            var tab = document.getElementById("tab");             var rowLength = tab.rows.length;            &

9、#160;var columnLength = tab.rows1.cells.length;               for (var i = 0; i < rowLength; i+)                 if (i = 0)     

10、;                var oTd = tab.rows0.insertCell(columnLength);                     oTd.innerHTML = "<div align=&

11、#39;center' style='width:40px'><a href='javascript:' onclick="DeleteSignColumn(" + (+columnID) + ")">删除</a></div>"                  else if (i = 1) /第一列:序

12、号                     var oTd = tab.rows1.insertCell(columnLength);                     oTd.innerHTM

13、L = "<div style='background: #D3E6FE;width=100%;'>" + (+count) + "</div>"                  else if (i > 1)            

14、0;        var oTd = tab.rowsi.insertCell(columnLength);                     oTd.id = "column" + columnID;        &#

15、160;            oTd.innerHTML = "<textarea id=''  rows='4' style='width:150; height:40px;'></textarea>"               &

16、#160;                                    /添加一个行         var index = 1;     

17、    function AddNewRow()             var txtTRLastIndex = findObj("txtTRLastIndex", document);             var rowID = parseInt(txtTRLastIndex.value);

18、               var tab = findObj("tab", document);             var columnLength = tab.rows0.cells.length;          

19、     /添加行             var newTR = tab.insertRow(tab.rows.length);             newTR.id = "SignItem" + rowID;       

20、        for (var i = 0; i < columnLength; i+)                 if (i = 0) /第一列:序号                 

21、    newTR.insertCell(0).innerHTML = +index;                  else if (i > 0 && i < 4)                 

22、0;   newTR.insertCell(i).innerHTML = "<input id='textItem0' type='text' style='border: 0px' size='12' />"                       

23、0;          else if (i >= 4)                     newTR.insertCell(i).innerHTML = "<textarea id=''  rows='4' style='

24、;width:150; height:40px;'></textarea>"                                           &

25、#160; /添加列:删除按钮             var lastTd = newTR.insertCell(columnLength);             lastTd.innerHTML = "<div align='center' style='width:40px'><

26、a href='javascript:' onclick="DeleteSignRow('SignItem" + rowID + "')">删除</a></div>"               /将行号推进下一行            

27、 txtTRLastIndex.value = (rowID + 1).toString();                    /删除指定行         function DeleteSignRow(rowid)          

28、;   var tab = findObj("tab", document);             var signItem = findObj(rowid, document);               /获取将要删除的行的Index    

29、0;        var rowIndex = signItem.rowIndex;               /删除指定Index的行             tab.deleteRow(rowIndex);    

30、0;            /重新排列序号,如果没有序号,这一步省略             for (i = 2; i < tab.rows.length; i+)                

31、60;tab.rowsi.cells0.innerHTML = i - 1;                            -index                  

32、  /删除指定列         function DeleteSignColumn(columnId)             var tab = document.getElementById("tab");             v

33、ar columnLength = tab.rows1.cells.length;               /删除指定单元格              for (var i = 0; i < tab.rows.length; i+)        &

34、#160;        tab.rowsi.deleteCell(columnId);                            /重新排列序号,如果没有序号,这一步省略       &

35、#160;     var column = columnLength - 4;               for (var j = 1; j < column; j+)                 tab.rows1.cellsj +

36、3.innerHTML = "<div style='background: #D3E6FE;width=100%;'>" + j + "</div>"                            -count;    

37、                  /清空列表         function ClearAllSign()             /if (confirm('确定要清空所有吗?')   &

38、#160;         index = 0;             var tab = findObj("tab", document);             var rowscount = tab.rows.length;  &

39、#160;            /循环删除行,从最后一行往前删除             for (i = rowscount - 1; i > 1; i-)                 

40、tab.deleteRow(i);                            /重置最后行号为1             var txtTRLastIndex = findObj("txtTRLas

41、tIndex", document);             txtTRLastIndex.value = "1"               /预添加一行             Add

42、NewRow();             /              </script>二、HTML部分:?<div style="overflow: auto; height: 350px; width: 860px; padding: 10px;">     

43、0;   <table cellpadding="1" id="tab" cellspacing="0" bordercolor="#A3C0E8" border="1"            style="text-align: center">      

44、0;      <tr id="tr1">                 <td>                      

45、;                  </td>                 <td>              

46、;                          </td>                 <td>      

47、;                                  </td>               

48、0; <td>                                        </td>       

49、0;         <td>                                        <

50、/td>             </tr>             <tr id="trHeader">                 <t

51、d style="background: #D3E6FE">                     NO                 </td>     &

52、#160;           <td style="background: #D3E6FE">                     试验项目          &

53、#160;      </td>                 <td style="background: #D3E6FE">                  

54、   检验项目                 </td>                 <td style="background: #D3E6FE">     

55、                标准                 </td>                

56、60;<td style="background: #D3E6FE">                     1                 </td>    

57、         </tr>             <tr>                 <td>        &#

58、160;            1                 </td>                 <td>  &

59、#160;                  <input id='textItem0' type='text' style="border: 0px" size='12' />              &#

60、160;  </td>                 <td>                     <input id='checkItem0' type='t

61、ext' style="border: 0px" size='12' />                 </td>                 <td>    

62、0;                <input id='stand0' type='text' style="border: 0px" size='12' />                 &l

63、t;/td>                 <td>                     <textarea rows="4" id="" style="wid

64、th: 150px; height: 40px;"></textarea>                 </td>             </tr>         </tab

65、le>         <table cellpadding="1" cellspacing="0" bordercolor="#A3C0E8" border="1" style="text-align: center">             <tr>  

66、               <td style="background: #D3E6FE">                 </td>                 <td style="background: #D3E6FE">      &

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论