JavaScript 设置和获得Radio的选中值

[color=darkred]设置单选框默认值[/color]
function setCheckedValue(radioName, newValue) {
if(!radioName) return;
var radios = document.getElementsByName(radioName);
for(var i=0; i radios[i].checked = false;
if(radios[i].value == newValue.toString()) {
radios[i].checked = true;
}
}
}

[color=darkred]获得单选框选中值[/color]
function getRadioValue(radioName){//得到radio的值   
var obj=document.getElementsByName(radioName);
for(var i=0;i if(obj[i].checked){
alert(obj[i].value);
return obj[i].value;
}
}
}

你可能感兴趣的:(JavaScript)