js表格排序 & 去除字符串空格
// a:列数 bool:排序升序判断参数 true false Str:支持多列 function newUnitSort(a, bool, str) { var oTable = document.getElementById('ATEST'); var arr = []; for (var i = 0; i < oTable.tBodies[0].rows.length; i++) { arr[i] = oTable.tBodies[0].rows[i]; } if (bool) { if (str === "name") { nameSortUp = false; } if (str === "type") { typeSortUp = false; } if (str === "ip") { ipSortUp = false; } arr.sort(function(tr1, tr2) { var str1 = tr1.cells[a].innerHTML; var str2 = tr2.cells[a].innerHTML; if (str1.localeCompare(str2) === -1) { return -1; } else if (str1.toLocaleString().localeCompare(str2) === 1) { return 1; } else { return 0; } }); } else { if (str === "name") { nameSortUp = true; } if (str === "type") { typeSortUp = true; } if (str === "ip") { ipSortUp = true; } arr.sort(function(tr1, tr2) { var str1 = tr1.cells[a].innerHTML; var str2 = tr2.cells[a].innerHTML; if (str1.localeCompare(str2) === -1) { return 1; } else if (str1.toLocaleString().localeCompare(str2) === 1) { return -1; } else { return 0; } }); } for (var i = 0; i < arr.length; i++) { oTable.tBodies[0].appendChild(arr[i]); } }
去除字符串空格:
String.prototype.NoSpace = function()
{
return this.replace(/\s+/g, "");
};