js-表格(table)添加列、刪除列_第1頁
js-表格(table)添加列、刪除列_第2頁
js-表格(table)添加列、刪除列_第3頁
js-表格(table)添加列、刪除列_第4頁
js-表格(table)添加列、刪除列_第5頁
已閱讀5頁,還剩3頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

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;                    /添加一個(gè)列         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、號(hào)                     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;                                    /添加一個(gè)行         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) /第一列:序號(hào)                 

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>"               /將行號(hào)推進(jìn)下一行            

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

28、;   var tab = findObj("tab", document);             var signItem = findObj(rowid, document);               /獲取將要?jiǎng)h除的行的Index    

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

30、0;            /重新排列序號(hào),如果沒有序號(hào),這一步省略             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);                            /重新排列序號(hào),如果沒有序號(hào),這一步省略       &

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;            /循環(huán)刪除行,從最后一行往前刪除             for (i = rowscount - 1; i > 1; i-)                 

40、tab.deleteRow(i);                            /重置最后行號(hào)為1             var txtTRLastIndex = findObj("txtTRLas

41、tIndex", document);             txtTRLastIndex.value = "1"               /預(yù)添加一行             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">                     試驗(yàn)項(xiàng)目          &

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

54、   檢驗(yàn)項(xiàng)目                 </td>                 <td style="background: #D3E6FE">     

55、                標(biāo)準(zhǔn)                 </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等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論