为了账号安全,请及时绑定邮箱和手机立即绑定

对表格进行升降排序:为什么我只能点击排序一次?

对表格进行升降排序:为什么我只能点击排序一次?

牛魔王的故事 2018-12-07 00:00:49
<html xmlns="http://www.w3.org/1999/xhtml"><head runat="server">    <title></title>    <script type ="text/javascript" >        function sortTable(sTableID,iCol) {             var oTable = document.getElementById(sTableID);            var oTBody = oTable.tBodies[0];            var colDataRows = oTBody.rows;            var aTRs = new Array;            for (var i = 0; i < colDataRows.length; i++) {                aTRs[i] = colDataRows[i];            }            if (oTable.sortCol == iCol) {                aTRs.reverse();            } else {                aTRs.sort(generateCompareTRs(iCol));            }            var Fragment = document.createDocumentFragment();            for (var i = 0; i < aTRs.length; i++) {                Fragment.appendChild(aTRs[i]);            }            oTable.appendChild(Fragment);            oTable.sortCol = iCol;        }        function generateCompareTRs(iCol) {            return function comparesTRs(tv1, tv2) {                var sv1 = tv1.cells[iCol ].firstChild.nodeValue;                var sv2 = tv2.cells[iCol ].firstChild.nodeValue;                return sv1.localeCompare(sv2);            }        }                    </script></head><body>    <form id="form1" method ="post" action ="" >    <table border ="1" id ="tblSort" >   <thead >   <tr >   <th onclick ="sortTable('tblSort',0)" style ="cursor :pointer ">Last Name</th>   <th onclick ="sortTable('tblSort',1)" style ="cursor :pointer ">First Name</th>   </tr>   </thead>   <tbody >   <tr><td>Smith</td><td>John</td></tr>   <tr ><td>Johnson</td><td >Betty</td></tr>   <tr ><td >Henderson</td><td >Nathan</td></tr>   <tr><td>Williams</td><td >James</td></tr>   <tr><td>Gilliam</td><td>Michael</td></tr>   <tr><td>Walker</td><td >Matthew</td></tr>   </tbody>    </table>    </form></body></html>
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 481 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信