|
復(fù)制代碼 代碼如下:
/**
* @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,作為了函數(shù)的參數(shù)。這是硬編碼抽象化,有關(guān)硬編碼、抽象化的具體內(nèi)容見《DOM scripting》譯書的部分。
JavaScript技術(shù):javascript腳本編程解決考試分?jǐn)?shù)統(tǒng)計問題,轉(zhuǎn)載需保留來源!
鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請第一時間聯(lián)系我們修改或刪除,多謝。