CheckBox 选中取值以及回填

html:

                    <td align="left" style="word-wrap:break-word;word-break:break-all;" colspan="3">
                        <input name="ck" type="checkbox" value="1"/><span>按计划进行</span> 
                        <input name="ck" type="checkbox" value="2"/><span>进度顺利但有延误风险</span> 
                        <input name="ck" type="checkbox" value="3"/><span>延误</span> 
                    </td>

获取选中值:

1、CheckBox为单选:

$("input:checkbox:checked").val()
或者
$("input:[type='checkbox']:checked").val();
或者
$("input:[name='ck']:checked").val();

2、CheckBox为多选:

$('input:checkbox').each(function() {
if ($(this).attr('checked') ==true) {
alert($(this).val());
}
});

3、全选:

$('input:checkbox').each(function() {
$(this).attr('checked', true);
});

4、全不选:

$('input:checkbox').each(function () {
$(this).attr('checked',false);
});

5、CheckBox回填:

$('input:checkbox:first').attr("checked",'checked');
或者
$('input:checkbox').eq(‘+索引变量+’).attr("checked",'true');
或者
$('input:checkbox[value='+CheckBox值+']').attr('checked','true');
多个回填:
$('input:radio').slice(0,2).attr('checked','true');

6、CheckBox只能单选

$(":checkbox").click(function(){
  if($(this).is(':checked')){
    $(this).attr('checked',true).siblings().attr('checked',false);
  }
});

 





 

转载于:https://www.cnblogs.com/ckxlovejava/p/7872478.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值