簡單來說就是逐一比對相同name屬性的input控制項
HTML part:
<form id="demoForm" method="post" action="...">
<input type="radio" name="statisticType" value="region" checked="checked" />依地區
<input type="radio" name="statisticType" value="time" />依時間<br />
</form>
JavaScript part:
var sType;
var demo = document.getElementById("demoForm");
for (var i = 0; i < demo.statisticType.length; i++) {
if (demo.statisticType[i].checked) {
sType = demo.statisticType[i].value;
break;
}
}
alert(sType);
HTML part:
<form id="demoForm" method="post" action="...">
<input type="radio" name="statisticType" value="region" checked="checked" />依地區
<input type="radio" name="statisticType" value="time" />依時間<br />
</form>
JavaScript part:
var sType;
var demo = document.getElementById("demoForm");
for (var i = 0; i < demo.statisticType.length; i++) {
if (demo.statisticType[i].checked) {
sType = demo.statisticType[i].value;
break;
}
}
alert(sType);
留言
張貼留言