radio
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript">
function btnClick() {
var radios = document.getElementsByName("gender");
//在JS中,for (var item in array)并不像C#中的foreach,不会遍历每个元素,而是遍历key
// for (var item in array) {
// if (item.isChecked) {
// alert(item.value);
// }
for(var i=0;i<radios.length;i++){
var radio = radios[i];
alert(radio.value);
}
}
</script>
</head>
<body>
<input type="radio" name="gender" value="男" />男
<input type="radio" name="gender" value="保密" />保密
<input type="radio" name="gender" value="女" />女
<input type="button" value="当前性别" onclick="btnClick()" />
</body>
</html>