js判断checkbox和select和radio的值
//取复选框checkbox选中的值
var s = document.getElementsByName("search");
var s2 = "";
var nowValue = "";
for( var i = 0; i < s.length; i++ )
{
if ( s[i].checked ){
s2 += s[i].value+',';
}
}
nowValue = s2.substring(0,s2.length-1);
//给复选框checkbox赋初值
function setNowType(type)
{
var mySel=document.getElementsByName('search');
for(var i=0;i<mySel.length;i++)
{
var me=mySel[i].value;
if(type.indexOf(me) != -1)
{
mySel[i].checked=true;
}
}
}
//取下拉菜单select选中的值
var mySel=document.getElementById('infoTypes');
var nowValue=mySel.options[mySel.selectedIndex].value;
//给下拉菜单select赋初值
function setNowType_old(type)
{
var mySel=document.getElementById('infoTypes');
for(var i=0;i<mySel.options.length;i++)
{
var me=mySel.options[i];
if(me.value==type)
{
me.selected=true;
}
}
}
//取单选按钮radio选中的值
function radio(){
var radio = document.getElementsByName("radio");
var radioLength = radio.length;
alert(radioLength);
for(var i = 0;i < radioLength;i++){
if(radio[i].checked){
var radioValue = radio[i].value;
alert(radioValue);
}
}
}