ckxlovejava

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);
  }
});

 






分类:

技术点:

相关文章:

  • 2022-12-23
  • 2021-05-24
  • 2021-12-23
  • 2022-12-23
  • 2021-12-23
猜你喜欢
  • 2022-12-23
  • 2021-06-04
  • 2022-01-22
相关资源
相似解决方案