JavaScript 设置和获得Radio的选中值
设置单选框默认值:
function setCheckedValue(radioName, newValue) {
if(!radioName) return;
var radios = document.getElementsByName(radioName);
for(var i=0; i<radios.length; i++) {
radios.checked = false;
if(radios.value == newValue.toString()) {
radios.checked = true;
}
}
}
获得单选框选中值:
01.function getRadioValue(radioName){//得到radio的值
02. var obj=document.getElementsByName(radioName);
03. for(var i=0;i<obj.length;i++){
04. if(obj.checked){
01. alert(obj.value);
01. return obj.value;
01. }
02. }
03. }