html的for循环嵌套实现排序

时间:2022-01-01 20:30:14
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>for循环嵌套实现排序</title>l
</head>

<body>

<script language="javascript">
<!--
// 定义变量引用一个数组对象
var oMyArray = new Array( 13, 55, 37, 33, 45, 9, 60, 21, 10 );
// 输出排序前的数组
document.write( "排序前:" + oMyArray );
// 开始排序
for ( index in oMyArray )
{
for ( i in oMyArray )
{
if( oMyArray[index]>oMyArray[i] )
{
nTemp = oMyArray[index];
oMyArray[index] = oMyArray[i];
oMyArray[i] = nTemp;
}
}
}
// 输出排序后的数组
document.write( "<br>排序后:" + oMyArray );
-->
</script>
</body>
</html>