测试通过 立刻给分!

解决方案 »

  1.   

    function sortTable(col, tableToSort)
      {
      //alert(event.ercElement.innerText);
        var iCurCell = col + tableToSort.cols;
        var totalRows = tableToSort.rows.length;
        alert(iCurCell);
        var bSort = 0;
        var colArray = new Array();
        var oldIndex = new Array();
        var indexArray = new Array();
        var bArray = new Array();
        var newRow;
        var newCell;
        var i;
        var c;
        var j;
        // ** POPULATE THE ARRAY colArray WITH CONTENTS OF THE COLUMN SELECTED
        for (i=1; i < tableToSort.rows.length; i++)
          {
            colArray[i - 1] = tableToSort.rows(i).cells(iCurCell).innerText;//setDataType(tableToSort.cells(iCurCell).innerText);
            //alert(colArray[i - 1]);
            iCurCell = iCurCell + tableToSort.cols;
          }
        // ** COPY ARRAY FOR COMPARISON AFTER SORT
        for (i=0; i < colArray.length; i++)
          {
            bArray[i] = colArray[i];
          }
        // ** SORT THE COLUMN ITEMS
        //alert ( colArray );
        colArray.sort();
        //alert ( colArray );
        for (i=0; i < colArray.length; i++)
        {
         tableToSort.rows(i+1).cells(col).innerText=colArray[i];
        }
    }
      

  2.   

    function setDataType(cValue)
      {
        // THIS FUNCTION CONVERTS DATES AND NUMBERS FOR PROPER ARRAY
        // SORTING WHEN IN THE SORT FUNCTION
        var isDate = new Date(cValue);
        if (isDate == "NaN")
          {
            if (isNaN(cValue))
              {
                // THE VALUE IS A STRING, MAKE ALL CHARACTERS IN
                // STRING UPPER CASE TO ASSURE PROPER A-Z SORT
                cValue = cValue.toUpperCase();
                return cValue;
              }
            else
              {
                // VALUE IS A NUMBER, TO PREVENT STRING SORTING OF A NUMBER
                // ADD AN ADDITIONAL DIGIT THAT IS THE + TO THE LENGTH OF
                // THE NUMBER WHEN IT IS A STRING
                var myNum;
                myNum = String.fromCharCode(48 + cValue.length) + cValue;
                return myNum;
              }
            }
      else
          {
            // VALUE TO SORT IS A DATE, REMOVE ALL OF THE PUNCTUATION AND
            // AND RETURN THE STRING NUMBER
            //BUG - STRING AND NOT NUMERICAL SORT .....
            // ( 1 - 10 - 11 - 2 - 3 - 4 - 41 - 5  etc.)
            var myDate = new String();
            myDate = isDate.getFullYear() + " " ;
            myDate = myDate + isDate.getMonth() + " ";
            myDate = myDate + isDate.getDate(); + " ";
            myDate = myDate + isDate.getHours(); + " ";
            myDate = myDate + isDate.getMinutes(); + " ";
            myDate = myDate + isDate.getSeconds();
            //myDate = String.fromCharCode(48 + myDate.length) + myDate;
            return myDate ;
          }
      }
      

  3.   

    To:  goody9807  在页面中如何调用?