您的位置:首页 > Web前端 > JavaScript

javascript脚本编程解决考试分数统计问题

2008-10-18 00:00 375 查看
/** 
* @author georgewing 
*/ 
function prepareCheckBox() { 
document.getElementById("submit").onclick = function() { 
selectedCheckBox(4); 
} 
} 
function selectedCheckBox(x) { 
var oInput = document.getElementsByTagName("input"); 
var iTotal = 0; 
for(var i=0;i<oInput.length;i++) { 
if(oInput[i].className == "checkedRadio") { 
if(oInput[i].checked) { 
//add x point 
iTotal = iTotal + x; 
} 
else { 
// add 0 point 
iTotal = iTotal + 0; 
} 
} 

} 
document.getElementById("Total").setAttribute("value", iTotal); 
alert(iTotal); 
}

提示:把常量4抽象化为变量x,作为了函数的参数。这是硬编码抽象化,有关硬编码、抽象化的具体内容见《DOM scripting》译书的部分。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: