js 选中radiobutton 拉菜单 复选框 下拉列 单选按钮 值
//选中radiobutton的某个值
function ChooseRadioValue(radioName,Value)
{
var radio = document.getElementsByName(radioName);
for(var i = 0;i < radio.length;i++)
{
if(radio[i].value == Value)
radio[i].checked = true;
}
}//选中下拉菜单的指定值
function ChooseSelectValue(selectName,Value)
{
var ddl = oo(selectName);
for(var i = 0;i < ddl.length;i++)
{
if(ddl.options[i].value == Value)
ddl.selectedIndex = i;
}
}
//选中 的指定值
function ChooseCheckBoxValue(checkboxName,Value)
{
if(Value == '') return;
var ary = Value.split(',');
var cehckbox = document.getElementsByName(checkboxName);
for(var k = 0; k < ary.length;k++)
{
for(var i = 0;i < cehckbox.length;i++)
{
if(cehckbox[i].value == ary[k])
cehckbox[i].checked = true;
}
}
}//获取下拉列表文字
function GetSelectText(selectId)
{
try
{
var sel = oo(selectId);
return sel.options[sel.selectedIndex].text;
}catch(e){ return "";}
}
//获取下拉列表值
function GetSelectValue(selectId)
{
try
{
var sel = oo(selectId);
return sel.options[sel.selectedIndex].value;
}
catch(e)
{
return "";
}
}
//获取复选框值function GetCheckBoxValue(chkName)
{
var chk = document.getElementsByName(chkName);
var str = "";
for (var i = 0;i < chk.length;i++)
if(chk[i].checked)
str += chk[i].value + ",";
if(str != "") str = str.substr(0,str.length-1);
return str;
}
//获取列表框值
function GetListValue(listId)
{
var sel = oo(listId);
var str = "";
for (i=0;i<sel.length;i++)
if(sel.options[i].selected)
str += sel.options[i].value + "|";
if(str != "") str = str.substr(0,str.length-1);
return str;
}//获取单选按钮值
function GetRadioValue(radioName)
{
var radio = document.getElementsByName(radioName);
for (i=0;i<radio.length;i++)
if(radio[i].checked)
return radio[i].value;
return "";
}
//获取单选按钮对象
function GetRadioObj(radioName)
{
var radio = document.getElementsByName(radioName);
for (i=0;i<radio.length;i++)
if(radio[i].checked)
return radio[i];
return "";
}