<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    blog.Toby

      BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
      130 隨筆 :: 2 文章 :: 150 評論 :: 0 Trackbacks
    javascript
    -------------------------------------------
    
    var dom = (document.getElementsByTagName) ? true : false;
    var ie = (document.getElementsByTagName && document.all) ? true : false;
    var arrowUp, arrowDown;
    
    if (ie || dom)
     initSortTable();
    
    function initSortTable() {
     arrowUp = document.createElement("SPAN");
     var tn = document.createTextNode("▲");
     arrowUp.appendChild(tn);
     arrowUp.className = "arrow";
    
     arrowDown = document.createElement("SPAN");
     var tn = document.createTextNode("▼");
     arrowDown.appendChild(tn);
     arrowDown.className = "arrow";
    }
    
    
    
    function sortTable(tableNode, nCol, bDesc, sType) {
     var tBody = tableNode.tBodies[0];
     var trs = tBody.rows;
     var trl= trs.length;
     var a = new Array();
    
     for (var i = 0; i < trl; i++) {
     a[i] = trs[i];
     }
    
     var start = new Date;
     window.status = "Sorting data...";
     a.sort(compareByColumn(nCol,bDesc,sType));
     window.status = "Sorting data done";
    
     for (var i = 0; i < trl; i++) {
     tBody.appendChild(a[i]);
     window.status = "Updating row " + (i + 1) + " of " + trl +
     " (Time spent: " + (new Date - start) + "ms)";
     }
    
     // check for onsort
     if (typeof tableNode.onsort == "string")
     tableNode.onsort = new Function("", tableNode.onsort);
     if (typeof tableNode.onsort == "function")
     tableNode.onsort();
    }
    
    function CaseInsensitiveString(s) {
     return String(s).toUpperCase();
    }
    
    function parseDate(s) {
     return Date.parse(s.replace(/\-/g, '/'));
    }
    
    /* alternative to number function
     * This one is slower but can handle non numerical characters in
     * the string allow strings like the follow (as well as a lot more)
     * to be used:
     * "1,000,000"
     * "1 000 000"
     * "100cm"
     */
    
    function toNumber(s) {
     return Number(s.replace(/[^0-9\.]/g, ""));
    }
    
    function compareByColumn(nCol, bDescending, sType) {
     var c = nCol;
     var d = bDescending;
    
     var fTypeCast = String;
    
     if (sType == "Number")
     fTypeCast = Number;
     else if (sType == "Date")
     fTypeCast = parseDate;
     else if (sType == "CaseInsensitiveString")
     fTypeCast = CaseInsensitiveString;
    
     return function (n1, n2) {
     if (fTypeCast(getInnerText(n1.cells[c])) < fTypeCast(getInnerText(n2.cells[c])))
     return d ? -1 : +1;
     if (fTypeCast(getInnerText(n1.cells[c])) > fTypeCast(getInnerText(n2.cells[c])))
     return d ? +1 : -1;
     return 0;
     };
    }
    
    function sortColumnWithHold(e) {
     // find table element
     var el = ie ? e.srcElement : e.target;
     var table = getParent(el, "TABLE");
    
     // backup old cursor and onclick
     var oldCursor = table.style.cursor;
     var oldClick = table.onclick;
    
     // change cursor and onclick
     table.style.cursor = "wait";
     table.onclick = null;
    
     // the event object is destroyed after this thread but we only need
     // the srcElement and/or the target
     var fakeEvent = {srcElement : e.srcElement, target : e.target};
    
     // call sortColumn in a new thread to allow the ui thread to be updated
     // with the cursor/onclick
     window.setTimeout(function () {
     sortColumn(fakeEvent);
     // once done resore cursor and onclick
     table.style.cursor = oldCursor;
     table.onclick = oldClick;
     }, 100);
    }
    
    function sortColumn(e) {
     var tmp = e.target ? e.target : e.srcElement;
     var tHeadParent = getParent(tmp, "THEAD");
     var el = getParent(tmp, "TD");
    
     if (tHeadParent == null)
     return;
    
     if (el != null) {
     var p = el.parentNode;
     var i;
    
     // typecast to Boolean
     el._descending = !Boolean(el._descending);
    
     if (tHeadParent.arrow != null) {
     if (tHeadParent.arrow.parentNode != el) {
     tHeadParent.arrow.parentNode._descending = null; //reset sort order
     }
     tHeadParent.arrow.parentNode.removeChild(tHeadParent.arrow);
     }
    
     if (el._descending)
     tHeadParent.arrow = arrowUp.cloneNode(true);
     else
     tHeadParent.arrow = arrowDown.cloneNode(true);
    
     el.appendChild(tHeadParent.arrow);
    
    
    
     // get the index of the td
     var cells = p.cells;
     var l = cells.length;
     for (i = 0; i < l; i++) {
     if (cells[i] == el) break;
     }
    
     var table = getParent(el, "TABLE");
     // can't fail
    
     sortTable(table,i,el._descending, el.getAttribute("type"));
     }
    }
    
    
    function getInnerText(el) {
     if (ie) return el.innerText; //Not needed but it is faster
    
     var str = "";
    
     var cs = el.childNodes;
     var l = cs.length;
     for (var i = 0; i < l; i++) {
     switch (cs[i].nodeType) {
     case 1: //ELEMENT_NODE
     str += getInnerText(cs[i]);
     break;
     case 3: //TEXT_NODE
     str += cs[i].nodeValue;
     break;
     }
    
     }
    
     return str;
    }
    
    function getParent(el, pTagName) {
     if (el == null) return null;
     else if (el.nodeType == 1 && el.tagName.toLowerCase() == pTagName.toLowerCase()) // Gecko bug, supposed to be uppercase
     return el;
     else
     return getParent(el.parentNode, pTagName);
    }
    //-->
    
    -------------------------------------------
    
    TABLE onclick="sortColumn(event)
    -------------------------------------------
    tr 加入 THEAD 標簽
    -------------------------------------------
    有時候js能實現些很好的功能。
    缺點:當有負數時,不能正確排序 
            有時客戶端適當用下js可有很好的效果
             如:js array
    <script language=JavaScript>
     var codes = new Array(new Array(<%= len %>),new Array(<%= len %>),new Array(<%= len %>));
    <%
     for(int i=0; i<len; i++)
     {
    %>
     codes[0][<%= i %>] = "<%= stocks[i][0] %>";
     codes[1][<%= i %>] = "<%= StringUtil.getUnicode(stocks[i][1]) %>";
     codes[2][<%= i %>] = "<%= stocks[i][2] %>";
    <%
     }
    %>
    </script>
    甚至可寫js類
    posted on 2005-12-28 14:26 渠上月 閱讀(1411) 評論(0)  編輯  收藏 所屬分類: js tips
    主站蜘蛛池模板: 一级女人18片毛片免费视频| 亚洲精品无码久久久久YW| 99re6在线视频精品免费| 在线亚洲精品福利网址导航| 国产精品九九久久免费视频 | 欧洲乱码伦视频免费| 亚洲国产成人综合| 女人18毛片水真多免费看| 亚洲av永久无码一区二区三区| 国产高清在线免费视频| 免费无遮挡无码视频在线观看| 亚洲偷自拍拍综合网| a级毛片黄免费a级毛片| 亚洲国产美女在线观看 | 一区二区三区四区免费视频| 亚洲美女视频网址| 精品久久久久国产免费| 久久精品亚洲日本波多野结衣| 亚洲日本一区二区一本一道 | 搡女人免费视频大全| 精品成人一区二区三区免费视频 | a毛片免费全部播放完整成| 久久精品国产亚洲AV嫖农村妇女| 69av免费视频| 羞羞漫画页面免费入口欢迎你 | 天天摸夜夜摸成人免费视频| 国产亚洲Av综合人人澡精品| 337p日本欧洲亚洲大胆裸体艺术| 水蜜桃视频在线观看免费播放高清| 亚洲欧洲日产国码在线观看| www.亚洲精品| 95老司机免费福利| 羞羞视频免费网站入口| 亚洲黄网在线观看| 亚洲片一区二区三区| 18观看免费永久视频| 免费人成再在线观看网站 | 亚洲日韩精品无码专区加勒比☆ | 久久久青草青青国产亚洲免观| 99久久久国产精品免费牛牛四川| 亚洲乱色伦图片区小说|