<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>New Web Project</title>
<script type="text/javascript" charset="UTF-8">
//排序从大到小排序(注意:JS数组内的元素是按字符串的形式比较的)
var arr = [1, 12, 3, 6, 8, 90, 34, 2];
function compare(value1, value2) {
if (value1 > value2) {
return true;
} else if (value1 < value2) {
return false;
} else {
return false;
}
}
//按元素从小到大排序(正序排序)
arr.sort(compare);
alert(arr);
</script>
</head>
<body>
<h1>New Web Project Page</h1>
</body>
</html>
js排序
最新推荐文章于 2024-09-10 00:44:46 发布