复选框(check box)是一种可同时选中多项的基础控件。
代码
<label>
<input onclick="getReason();" name="isPillbox" type="checkbox" value="1"/>JAVA
</label>
<label>
<input onclick="getReason();" name="isPillbox" type="checkbox" value="2"/>C++
</label>
页面显示
赋值(全部选中)
$('input:checkbox').each(function() {
$(this).attr('checked', true);
});
获取选中值(字符串形式,以逗号隔开)
function getReason(){
obj = $('input[name="isPillbox"]');
check_val = [];
obj.each(function(i){
if($(this).is(":checked")){
check_val.push($(this).val());
}
});
isPillbox=check_val.toString();//已字符串形式获取
alert(isPillbox);
}
最后
以上就是丰富白云最近收集整理的关于checkbox 复选框 取值 赋值的全部内容,更多相关checkbox内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复