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 < l; i++) {
switch (cs[i].nodeType) {
case 1: // ELEMENT_NODE
str += ts_getInnerText(cs[i]);
break;
case 3: // TEXT_NODE
str += cs[i].nodeValue;
break;
}
}
return str;
}
现在当我在IE中调用此函数时,它总是会得到未定义的值,这会在consol上引发错误,所以我添加了一个未定义的检查。
function ts_sort_caseinsensitive(a, b) {
if (a.cells.length == b.cells.length) {
if (!(typeof ts_getInnerText(a.cells[SORT_COLUMN_INDEX]) == 'undefined')) {
aa = ts_getInnerText(a.cells[SORT_COLUMN_INDEX]).toLowerCase();
bb = ts_getInnerText(b.cells[SORT_COLUMN_INDEX]).toLowerCase();
if (aa == bb) {
return 0;
}
if (aa < bb) {
return -1;
}
return 1;
}
}
}
之后,列开始按点击但不正确排序..例如我必须单击两次才能将其排序为asc或desc顺序。