<!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=utf-8"
/>
<title>无标题文档</title>
<style
type="text/css">
<!--
body
{
background-color:
#0000ff
}
-->
</style>
</head>
<body>
<img
src="./images/sky.gif"
width="80"
height="80"
/>
本网页支持简体中文
</body>
</html>
<!doctype html><html lang="en">
<head>
<meta charset="utf-8">
<title>0929</title>
</head>
<body>
<input type="text" value="1,2,716,2,1,56" id="num"><!--数字之间用英文逗号区分-->
<button onclick="max()">求最大值</button>
<button onclick="min()">求最小值</button>
<button onclick="avg()">求平均值</button>
</body>
<script>
function max(){
var num = document.getElementById('num').value
var numbers = num.split(",")
var maxInNumbers = Math.max.apply(Math, numbers)
alert('最大数是:'+maxInNumbers)
}
function min(){
var num = document.getElementById('num').value
var numbers = num.split(",")
var minInNumbers = Math.min.apply(Math, numbers)
alert('最小数是:'+minInNumbers)
}
function avg(){
var num = document.getElementById('num').value
var numbers = num.split(",")
var sum=0
for (var i = 0i <numbers.lengthi++) {
sum+=parseInt(numbers[i])
}
var avg=(sum/numbers.length)
alert(avg)
}
</script>
</html>
第二题没看懂需求(本人读书少)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)