我没有发布所有的HTML代码,但我确实给出了HTML示例。
如果我有4页,则可以获得每页检查的单选按钮的所有值。
第1页
<table>
<tbody>
<tr class="choices1">
<td align="center"><input id="r1" name="radio" type="radio" value="Stop" /></td>
<td>Stop</td>
</tr>
<tr class="choices2">
<td align="center"><input id="r2" name="radio" type="radio" value="Go" /></td>
<td>Go</td>
</tr>
<tr class="choices1">
<td align="center"><input id="r3" name="radio" type="radio" value="Ready" /></td>
<td>Ready</td>
</tr>
<tr class="choices2">
<td align="center"><input id="r4" name="radio" type="radio" value="Fly" /></td>
<td>Fly</td>
</tr>
</tbody>
</table>
我的代码
// this is the code that i'm using to get the value of the radio button that is checked.
// this code is working for 1 page only.
function findSelection(field) {
var test = document.getElementsByName(field);
var q1 = 0, q2 = 0;
var score = 0;
for (i=0; i < test.length; i++) {
if (test[i].checked==true) {
return (test[i].value);
}
}
}
function submit() {
var choice = findSelection("radio");
alert(choice);
return false;
}
答案 0 :(得分:0)
您可以将onClick事件绑定到输入元素。
<table>
<tbody>
<tr class="choices1">
<td align="center">
<input id="r1" name="radio" type="radio" value="Stop" onclick="myFunction(this);" />
</td>
<td>Stop</td>
</tr>
<tr class="choices2">
<td align="center">
<input id="r2" name="radio" type="radio" value="Go" onclick="myFunction(this);" />
</td>
<td>Go</td>
</tr>
<tr class="choices1">
<td align="center">
<input id="r3" name="radio" type="radio" value="Ready" onclick="myFunction(this);" />
</td>
<td>Ready</td>
</tr>
<tr class="choices2">
<td align="center">
<input id="r4" name="radio" type="radio" value="Fly" onclick="myFunction(this);" />
</td>
<td>Fly</td>
</tr>
</tbody>
onclick函数可以调用函数来提醒值。
function myFunction(id) {
alert(id.value);
}