var mydate=new Date();
var weekday=["星期日","星期一","星期二","星期三","星期四","星期五","星期六"];
var month=["1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月"];
var scoreStr = "小明:87;小花:81;小红:97;小天:76;小张:74;小小:94;小西:90;小伍:76;小迪:64;小曼:76";
var str=scoreStr.split(";");
//成绩是一长窜的字符串不好处理,找规律后分割放到数组里更好操作哦
for(var i=0,sum=0;i<str.length;i++){
var myarr=new Array();
myarr[i]=str[i].slice(3);
sum=sum+parseInt(myarr[i]);
}
var myavg=sum/str.length;
document.write(mydate.getFullYear() +"年"+month[mydate.getMonth()]+mydate.getDay()+"日"+" ");
document.write(weekday[mydate.getDay()]+"--班级总分为:"+ Math.floor(myavg));
你好,str[i].slice(3);这个为什么可以用.连接slice起来一起合用啊
中文字符确实很烦,而且有时候输入法会误触,如果是win10系统可以设置第二种键盘布局,来避免这种情况