There are a total of 25 questions for this exam, each of which is a two-choice and One-choice question with a total score of 100. The javascript code is as follows:
The Code is as follows:
/**
* @ 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 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 );
}
Tip: the constant 4 is abstracted into variable x as a parameter of the function. This is hard encoding abstraction. For details about hard encoding and abstraction, see the translated content of DOM scripting.