如何在JavaScript中编写sort by选项? [英] How do I write sort by option in JavaScript?

查看:64
本文介绍了如何在JavaScript中编写sort by选项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

实际上我已经在我的javascript中编写了sort by选项。它不适用于Interent Explorer 9版本,但它也适用于所有其他浏览器和IE 11。是否需要为此提供标签?



Actually I already wrote the sort by option in my javascript. It is not working in Interent Explorer 9 version but it's working all other browsers and IE 11 as well. Is there any tags need to give for that?

<html>

<head>
<meta http-equiv="content-type" content="text/html;charset=Windows-1252">
<script type="text/javascript">
var people, asc1 = 1, asc2 = 1;
window.onload = function() {
people = document.getElementById("people");
}

function sort_table(tbody, col, asc) {
var rows = tbody.rows, rlen = rows.length, arr = new Array(), i, j, cells, clen;
// fill the array with values from the table
for (i = 0; i < rlen; i++) {

cells = rows[i].cells;

clen = cells.length;

arr[i] = new Array();

for (j = 0; j < clen; j++) {

arr[i][j] = cells[j].innerHTML;

}

}

// sort the array by the specified column number (col) and order (asc)

arr.sort(function(a, b) {

return (a[col] == b[col]) ? 0

: ((a[col] > b[col]) ? asc : -1 * asc);
});
// replace existing rows with new rows created from the sorted array
for (k = 0; k < rlen; k++) {

rows[k].innerHTML = "<td class='tdclass'>"

+ arr[k].join("</td><td class='tdclass'>") + "</td>";
}

}

function selectRadio() {
var radioValue="";
if (document.getElementById('radioId1').checked) {
sort_table(people, 2, asc1); asc1 *= -1; asc2 = 1;
} else if (document.getElementById('radioId2').checked) {
sort_table(people, 2, asc2); asc2 *= -1; asc1 = 1;
}


}
</script>

<body>
<br/>
<br/>
<table>
<tr>
<td class="tdheadclass"><input type="button" value="Main Menu" /><span class="tab"></span></td>
<td class="tdheadclass"><input type="button" value="New Search" /><span class="tab"></span></td>
<td class="tdheadclass">
<input type="radio" id="radioId1" name="radioId" value="Id" checked>Id
<input type="radio" id="radioId2" name="radioId" value="Email Id">Email Id<span class="tabLess"></span>
<input type="button" value="Sort by" />
</td>
<td class="tdheadclass"><input type="button" value="Save As" /><span class="tab"></span></td>

推荐答案

看起来你已经知道答案了

looks like you already know the answer to
引用:

我该怎么写sort通过JavaScript中的选项?

How do I write sort by option in JavaScript?

因为你说

Since you said

引用:

它正在运行所有其他浏览器和IE 11还有。

it's working all other browsers and IE 11 as well.

可能是你应该提供你的代码询问如何制作它适用于IR9。

May be you should provide your code ask how to make it work with IR9.


这篇关于如何在JavaScript中编写sort by选项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆