美文网首页
jquery获取复选框checkbox的值

jquery获取复选框checkbox的值

作者: 下班再说 | 来源:发表于2020-02-27 17:07 被阅读0次

js://js获取复选框值 

varobj = document.getElementsByName("interest");//选择所有name="interest"的对象,返回数组   

vars='';//如果这样定义var s;变量s中会默认被赋个null值

for(vari=0;i

if(obj[i].checked)//取到对象数组后,我们来循环检测它是不是被选中

s+=obj[i].value+',';//如果选中,将value添加到变量s中   

}

jquery://jquery获取复选框值 

var chk_value =[];//定义一个数组   

$('input[name="interest"]:checked').each(function(){//遍历每一个名字为interest的复选框,其中选中的执行函数   

chk_value.push($(this).val());//将选中的值添加到数组chk_value中   

});

相关文章

网友评论

      本文标题:jquery获取复选框checkbox的值

      本文链接:https://www.haomeiwen.com/subject/zbdxhhtx.html