• <fieldset id="8imwq"><menu id="8imwq"></menu></fieldset>
  • <bdo id="8imwq"><input id="8imwq"></input></bdo>
    最新文章專題視頻專題問答1問答10問答100問答1000問答2000關(guān)鍵字專題1關(guān)鍵字專題50關(guān)鍵字專題500關(guān)鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關(guān)鍵字專題關(guān)鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
    問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
    當(dāng)前位置: 首頁 - 科技 - 知識(shí)百科 - 正文

    tableinsertRow、deleteRow定義和用法總結(jié)_javascript技巧

    來源:懂視網(wǎng) 責(zé)編:小采 時(shí)間:2020-11-27 21:23:13
    文檔

    tableinsertRow、deleteRow定義和用法總結(jié)_javascript技巧

    tableinsertRow、deleteRow定義和用法總結(jié)_javascript技巧:表格有幾行: var trCnt = table.rows.length; (table為Id ) 每行有幾列:for (var i=0; itable.rows[i].cells.length; javascript操作table: insertRow(),deleteRow(),insertCell(),deleteCell()方法 tab
    推薦度:
    導(dǎo)讀tableinsertRow、deleteRow定義和用法總結(jié)_javascript技巧:表格有幾行: var trCnt = table.rows.length; (table為Id ) 每行有幾列:for (var i=0; itable.rows[i].cells.length; javascript操作table: insertRow(),deleteRow(),insertCell(),deleteCell()方法 tab

    表格有幾行: var trCnt = table.rows.length; (table為Id )

    每行有幾列:for (var i=0; itable.rows[i].cells.length;

    javascript操作table:

    insertRow(),deleteRow(),insertCell(),deleteCell()方法

    table.insertRow()在IE下沒問題 但在firefox下就得改為table.insertRow(-1)
    同樣其相應(yīng)的insertCell()也要改為insertCell(-1)

    insertRow() 方法

    定義和用法

    insertRow() 方法用于在表格中的指定位置插入一個(gè)新行。

    語法

    tableObject.insertRow(index)

    返回值

    返回一個(gè) TableRow,表示新插入的行。

    說明

    該方法創(chuàng)建一個(gè)新的 TableRow 對(duì)象,表示一個(gè)新的 標(biāo)記,并把它插入表中的指定位置。

    新行將被插入 index 所在行之前。若index等于表中的行數(shù),則新行將被附加到表的末尾。

    如果表是空的,則新行將被插入到一個(gè)新的 段,該段自身會(huì)被插入表中。

    拋出

    若參數(shù) index 小于 0 或大于等于表中的行數(shù),該方法將拋出代碼為 INDEX_SIZE_ERR 的DOMException 異常 。

    例子
    代碼如下:

    < head>
    < script type="text/javascript">
    function insRow()
    {
    document.getElementById('myTable').insertRow(0)
    }
    < /script>
    < /head>

    < body>
    < table id="myTable" border="1">
    < tr>
    < td>Row1 cell1
    < td>Row1 cell2
    < /tr>
    < tr>
    < td>Row2 cell1
    < td>Row2 cell2
    < /tr>
    < /table>
    < br />
    < input type="button" onclick="insRow()"
    value="Insert new row">

    < /body>
    < /html>

    deleteCell()

    定義和用法

    deleteCell() 方法用于刪除表格行中的單元格( 元素)。

    語法

    tablerowObject.deleteCell(index)

    說明

    參數(shù) index 是要?jiǎng)h除的表元在行中的位置。

    該方法將刪除表行中指定位置的表元。

    拋出

    若參數(shù) index 小于 0 或大于等于行中的的表元數(shù),該方法將拋出代碼為 INDEX_SIZE_ERR 的DOMException異常。

    例子
    代碼如下:

    < head>
    < script type="text/javascript">
    function delRow()
    {
    document.getElementById('myTable').deleteRow(0)
    }
    < /script>
    < /head>
    < body>

    < table id="myTable" border="1">
    < tr>
    < td>Row1 cell1
    < td>Row1 cell2
    < /tr>
    < tr>
    < td>Row2 cell1
    < td>Row2 cell2
    < /tr>
    < /table>
    < br />
    < input type="button" onclick="delRow()"
    value="Delete first row">

    < /body>
    < /html>

    insertCell()

    定義和用法

    insertCell() 方法用于在 HTML 表的一行的指定位置插入一個(gè)空的 元素。

    語法

    tablerowObject.insertCell(index)

    返回值

    一個(gè) TableCell 對(duì)象,表示新創(chuàng)建并被插入的 元素。

    說明

    該方法將創(chuàng)建一個(gè)新的 元素,把它插入行中指定的位置。新單元格將被插入當(dāng)前位于 index 指定位置的表元之前。如果 index 等于行中的單元格數(shù),則新單元格被附加在行的末尾。

    請(qǐng)注意,該方法只能插入 數(shù)據(jù)表元。若需要給行添加頭表元,必須用 Document.createElement() 方法和 Node.insertBefore() 方法(或相關(guān)的方法)創(chuàng)建并插入一個(gè) 元素。

    拋出

    若參數(shù) index 小于 0 或大于等于行中的的表元數(shù),該方法將拋出代碼為 INDEX_SIZE_ERR 的DOMException異常。

    例子
    代碼如下:

    < head>
    < script type="text/javascript">
    function insCell()
    {
    var x=document.getElementById('tr2').insertCell(0)
    x.innerHTML="John"
    }
    < /script>
    < /head>
    < body>

    < table border="1">
    < tr id="tr1">
    < th>Firstname
    < th>Lastname
    < /tr>
    < tr id="tr2">
    < td>Peter
    < td>Griffin
    < /tr>
    < /table>
    < br />
    < input type="button" onclick="insCell()" value="Insert cell">

    < /body>
    < /html>

    deleteCell()

    定義和用法

    deleteCell() 方法用于刪除表格行中的單元格( 元素)。

    語法

    tablerowObject.deleteCell(index)

    說明

    參數(shù) index 是要?jiǎng)h除的表元在行中的位置。

    該方法將刪除表行中指定位置的表元。

    拋出

    若參數(shù) index 小于 0 或大于等于行中的的表元數(shù),該方法將拋出代碼為 INDEX_SIZE_ERR 的DOMException異常。

    例子
    代碼如下:

    < head>
    < script type="text/javascript">
    function delCell()
    {
    document.getElementById('tr2').deleteCell(0)
    }
    < /script>
    < /head>
    < body>

    < table border="1">
    < tr id="tr1">
    < th>Firstname
    < th>Lastname
    < /tr>
    < tr id="tr2">
    < td>Peter
    < td>Griffin
    < /tr>
    < /table>
    < br />
    < input type="button" onclick="delCell()" value="Delete cell">

    < /body>
    < /html>

    項(xiàng)目中的應(yīng)用:
    代碼如下:

    聲明:本網(wǎng)頁內(nèi)容旨在傳播知識(shí),若有侵權(quán)等問題請(qǐng)及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

    文檔

    tableinsertRow、deleteRow定義和用法總結(jié)_javascript技巧

    tableinsertRow、deleteRow定義和用法總結(jié)_javascript技巧:表格有幾行: var trCnt = table.rows.length; (table為Id ) 每行有幾列:for (var i=0; itable.rows[i].cells.length; javascript操作table: insertRow(),deleteRow(),insertCell(),deleteCell()方法 tab
    推薦度:
    標(biāo)簽: 定義 js javascript
    • 熱門焦點(diǎn)

    最新推薦

    猜你喜歡

    熱門推薦

    專題
    Top
    主站蜘蛛池模板: 亚洲欧洲国产精品你懂的| 精品国产一区二区三区在线观看| 99久久综合国产精品二区| 亚洲精品午夜无码电影网| 国产伦精品一区二区免费| 大伊香蕉精品一区视频在线 | 精品无人区麻豆乱码1区2区| 人妻VA精品VA欧美VA| 欧美日激情日韩精品| 国产精品久久久久jk制服| 无码精品人妻一区二区三区免费看| 久久国产香蕉一区精品| 国产精品 码ls字幕影视| 欧美亚洲国产精品第一页| 91精品国产综合久久精品| 精品性影院一区二区三区内射| 亚洲精品成人无码中文毛片不卡| 亚洲国产精品一区二区第一页免| 精品久久久久久无码中文野结衣| 91精品久久久久久无码| 五月花精品视频在线观看| 2020国产精品| 99精品视频在线| 99久久99这里只有免费费精品| 久久久久久国产精品免费无码| 亚洲AV无码成人精品区天堂| 亚洲日韩国产AV无码无码精品| 亚洲国产精品无码专区影院 | 99久久精品免费观看国产| 91精品国产色综合久久| 国产精品一区二区久久不卡| 蜜臀久久99精品久久久久久小说 | 色一乱一伦一图一区二区精品 | 国产精品午夜久久| 99精品国产福利在线观看| 亚洲国产精品婷婷久久| 久久福利青草精品资源站免费| 国产福利91精品一区二区三区| 91老司机深夜福利精品视频在线观看 | 国产成人精品久久亚洲高清不卡| 精品999久久久久久中文字幕|