F
fulio pen
Please open the following page:
http://www.pinyinology.com/zhongwen/test3.html
When opened, the data are not sorted, either numerically or
alphabetically. A head in the table, the numeral or the letter, has
to be pressed to get the data sorted by the column. Is there a way
that when the page is opened, the data will become automatically
sorted by the numeral column without pressing the head? Thanks.
Following is the code:
<script type='text/javascript'>
<!--
var sanjiao = new Array ();
for (var i=0; i<6; i++)
{
sanjiao = new Array();
}
sanjiao [0]["ID"] = "5";
sanjiao [0]["Pinyin"] = "d";
sanjiao [1]["ID"] = "2";
sanjiao [1]["Pinyin"] = "f";
sanjiao [2]["ID"] = "4";
sanjiao [2]["Pinyin"] = "b";
sanjiao [3]["ID"] = "1";
sanjiao [3]["Pinyin"] = "e";
sanjiao [4]["ID"] = "6";
sanjiao [4]["Pinyin"] = "a";
sanjiao [5]["ID"] = "3";
sanjiao [5]["Pinyin"] = "c";
function sortByID(a, b)
{
var A = a["ID"].toLowerCase().replace(/\d/g,""),
B = b["ID"].toLowerCase().replace(/\d/g,""),
C = a["ID"].replace(/\D/g,""),
D = b["ID"].replace(/\D/g,"");
if (A < B) return -1;
else if (A > B) return 1;
else if (C - D < 0) return -1;
else if (C - D > 0) return 1;
else return 0;
}
function sortByPinyin (a, b)
{
var A = a["Pinyin"].toLowerCase();
var B = b["Pinyin"].toLowerCase();
if (A < B) return -1;
if (A > B) return 1;
return 0;
}
var sortCriteria = location.search.substring(1);
if (sortCriteria && typeof window[sortCriteria] == "function")
sanjiao.sort(window[sortCriteria]);
//-->
</script>
</head>
<body>
<table border='1' align='left' style='margin-right:15px;'>
<caption>Numerals and Letters</caption>
<tr>
<th><a href="?sortByID">Numeral</a></th>
<th><a href="?sortByPinyin">Letter</a></th>
</tr>
<script type='text/javascript'>
<!--
for (var i=0; i<sanjiao.length; i++)
{
document.write(" <tr>");
document.write(" <td>" + sanjiao["ID"] + "</td>");
document.write(" <td class='pinyin'>" + sanjiao["Pinyin"] + "</
td>");
document.write(" </tr>");
}
//-->
</script>
</table>
http://www.pinyinology.com/zhongwen/test3.html
When opened, the data are not sorted, either numerically or
alphabetically. A head in the table, the numeral or the letter, has
to be pressed to get the data sorted by the column. Is there a way
that when the page is opened, the data will become automatically
sorted by the numeral column without pressing the head? Thanks.
Following is the code:
<script type='text/javascript'>
<!--
var sanjiao = new Array ();
for (var i=0; i<6; i++)
{
sanjiao = new Array();
}
sanjiao [0]["ID"] = "5";
sanjiao [0]["Pinyin"] = "d";
sanjiao [1]["ID"] = "2";
sanjiao [1]["Pinyin"] = "f";
sanjiao [2]["ID"] = "4";
sanjiao [2]["Pinyin"] = "b";
sanjiao [3]["ID"] = "1";
sanjiao [3]["Pinyin"] = "e";
sanjiao [4]["ID"] = "6";
sanjiao [4]["Pinyin"] = "a";
sanjiao [5]["ID"] = "3";
sanjiao [5]["Pinyin"] = "c";
function sortByID(a, b)
{
var A = a["ID"].toLowerCase().replace(/\d/g,""),
B = b["ID"].toLowerCase().replace(/\d/g,""),
C = a["ID"].replace(/\D/g,""),
D = b["ID"].replace(/\D/g,"");
if (A < B) return -1;
else if (A > B) return 1;
else if (C - D < 0) return -1;
else if (C - D > 0) return 1;
else return 0;
}
function sortByPinyin (a, b)
{
var A = a["Pinyin"].toLowerCase();
var B = b["Pinyin"].toLowerCase();
if (A < B) return -1;
if (A > B) return 1;
return 0;
}
var sortCriteria = location.search.substring(1);
if (sortCriteria && typeof window[sortCriteria] == "function")
sanjiao.sort(window[sortCriteria]);
//-->
</script>
</head>
<body>
<table border='1' align='left' style='margin-right:15px;'>
<caption>Numerals and Letters</caption>
<tr>
<th><a href="?sortByID">Numeral</a></th>
<th><a href="?sortByPinyin">Letter</a></th>
</tr>
<script type='text/javascript'>
<!--
for (var i=0; i<sanjiao.length; i++)
{
document.write(" <tr>");
document.write(" <td>" + sanjiao["ID"] + "</td>");
document.write(" <td class='pinyin'>" + sanjiao["Pinyin"] + "</
td>");
document.write(" </tr>");
}
//-->
</script>
</table>