<script type="text/javascript">
//<![CDATA[
function mySort(item1, item2)
{
if (item1 > item2) return 1;
if (item1 < item2) return -1;
if (item1 == item2) return 0;
}
myArray = new Array(3, 6, 8, 1, 2);
document.write("myArray before being sorted:<br>");
for (i=0; i<myArray.length; i++)
{
document.write("myArray[", i, "] : ", myArray[i], "<br>");
}
myArray.sort(mySort);
document.write("<br>myArray after being sorted:<br>");
for (i=0; i<myArray.length; i++)
{
document.write("myArray[", i, "] : ", myArray[i], "<br>");
}
//]]>
</script>
sort调用mySort定义的准则
排序准则
最新推荐文章于 2022-01-30 16:31:33 发布