分享以下代码,共同交流
<!DOCTYPE HTML>
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>系好安全带,准备启航</title>
<script type="text/javascript">
//通过javascript的日期对象来得到当前的日期,并输出。
var date=new Date();
var year=date.getFullYear()+"年";
var month=date.getMonth()+"月";
var date1=date.getDate()+"日";
//alert(date1);
var weekq=["星期一","星期二","星期三","星期四","星期五","星期六","星期天"];
var week=weekq[date.getDay()];
//alert(week);
var xinxi="小明:87;小花:81;小红:97;小天:76;小张:74;小小:94;小西:90;小五:76;小迪:64;小曼:76";
var fenshu=[xinxi.slice(3,5),xinxi.slice(9,11),xinxi.slice(15,17),xinxi.slice(21,23),xinxi.slice(27,29),xinxi.slice(33,35),xinxi.slice(39,41),xinxi.slice(45,47),xinxi.slice(51,53),xinxi.slice(57,59)];
// alert(fenshu);
var sum=0;
for(var i=0;i<fenshu.length-1;i++){
sum=sum+parseInt(fenshu[i]);
}
//alert(sum);
var avg=sum/fenshu.length;
document.write(year+month+date1+" "+week+"---班级平均分为"+avg+" ."+"总分为:"+sum);
</script>
</head>
<body>
</body>
</html>