IE支援原生交換兩行的位置

來源:互聯網
上載者:User

在IE的table,tbody,thead, tfoot中,它們都支援一個叫moveRow(indexToMove, destinationIndex)的API,第一個參數要移去的行號,第二個參數為當前的行號,行號即為rowIndex。有了,我們就可以簡捷地交換兩行位置,而不需要冗長的insertBefore(它還要根據是上移下是下移,修改參數呢)。

<br /><!doctype html><br /><html><br /> <head><br /> <title>交換行的位置 by 司徒正美</title><br /> <script><br /> window.onload = function(){<br /> var tb = document.getElementById("table");<br /> tb.moveRow(2,1)<br /> }<br /> </script><br /> <style><br /> .table{<br /> width:60%;<br /> border: 1px solid red;<br /> border-collapse: collapse;<br /> }<br /> .table td{<br /> border: 1px solid red;<br /> height: 20px;<br /> }<br /> </style><br /> </head><br /> <body><br /> <h1>行交換 by 司徒正美</h1><br /> <table class="table"><br /> <tbody id="table"><br /> <tr><br /> <td>0</td><br /> <td>One</td><br /> <td>dom.require</td><br /> </tr><br /> <tr id="2" ><br /> <td class="2">1</td><br /> <td>Two</td><br /> <td>ControlJS </td><br /> </tr><br /> <tr id="3" ><br /> <td class="3">2</td><br /> <td>Three</td><br /> <td>HeadJS</td><br /> </tr><br /> <tr id="4" ><br /> <td class="4">3</td><br /> <td>Four</td><br /> <td>LAB.js</td><br /> </tr><br /> <tr id="5" ><br /> <td class="5">4</td><br /> <td>Five</td><br /> <td>$script.js</td><br /> </tr><br /> <tr id="6" ><br /> <td class="6">5</td><br /> <td>Six</td><br /> <td>NBL.js</td><br /> </tr><br /> </tbody><br /> </table><br /> </body><br /></html><br />

運行代碼

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.