使用一段javascript对页面的表格排序,E文和数字类型的没问题,现重金悬赏中文解决方案
实现排序的代码在script脚本,由于javascript使用的是unicode编码,所以不能像SqlServer中一样,按拼音排序,
目前我有3个思路,1.javascript提取汉字拼音2.Ajax调用高级语言3.实在不行只能用sqlserver在取一次数据。
代码:
<script language= "javascript ">
addEvent(window, "load ", sortables_init);
var SORT_COLUMN_INDEX;
function sortables_init() {
// Find all tables with class sortable and make them sortable
if (!document.getElementsByTagName) return;
tbls = document.getElementsByTagName( "table ");
for (ti=0;ti <tbls.length;ti++) {
thisTbl = tbls[ti];
if ((( ' '+thisTbl.className+ ' ').indexOf( "sortable ") != -1) && (thisTbl.id)) {
//initTable(thisTbl.id);
ts_makeSortable(thisTbl);
}
}
}
function ts_makeSortable(table) {
if (table.rows && table.rows.length > 0) {
var firstRow = table.rows[0];
}
if (!firstRow) return;
// We have a first row: assume it 's the header, and make its contents clickable links
for (var i=0;i <firstRow.cells.length;i++) {
var cell = firstRow.cells[i];
var txt = ts_getInnerText(cell);
cell.innerHTML = ' <a href= "# " class= "sortheader " '+
'onclick= "ts_resortTable(this, '+i+ ');return false; "> ' +
txt+ ' <span class= "sortarrow "> </span> </a> ';
}
}
function ts_getInnerText(el) {
if (typeof el == "string ") return el;
if (typeof el == "undefined ") { return el };
if (el.innerText) return el.innerText; //Not needed but it is faster
var str = " ";
var cs = el.childNodes;
var l = cs.length;
for (var i = 0; i &nb