<html>
<head>
<meta charset="UTF-8" />
<title>test</title>
<script type="text/javascript">
var guys = function ()
{
var max = Number.MIN_VALUE, min = Number.MAX_VALUE
for ( var i = 0 i < 3 i++)
{
var number = prompt ("输入第 " + (i + 1) + " 个小于10的正整数: ", "")
if (isNaN (parseFloat (number)) || !isFinite (number))
{
alert ('输入非法,重新输入.')
i--
continue
}
max = max < number ? number : max
min = min > number ? number : min
}
alert ("最大值是:" + max + "\n最小值是: " + min)
}
guys ()
</script>
</head>
<body>
</body>
</html>
假设你有1-10个数var d = new Array()
d.push(1)
d.push(2)
d.push(3)
d.push(4)
d.push(5)
d.push(6)
d.push(7)
d.push(8)
d.push(9)
d.push(10)
d.sort(function compare(a, b) { return a - b})
document.writeln("最小值:"+d[0])
d.sort(function compare(a, b) { return b - a})
document.writeln("最大值:" + d[0])