weimingxin

jQuery设置checkbox 为选中状态

1设置第一个checkbox 为选中值
$(\'input:checkbox:first\').attr("checked",\'checked\');

或者
$(\'input:checkbox\').eq(0).attr("checked",\'true\');

2、设置最后一个checkbox为选中值
$(\'input:checkbox:last\').attr(\'checked\', \'checked\');

或者
$(\'input:checkbox:last\').attr(\'checked\', \'true\');

3、根据索引值设置任意一个checkbox为选中值
$(\'input:checkbox).eq(索引值).attr(\'checked\', \'true\');索引值=0,1,2....

或者
$(\'input:checkbox\').slice(1,2).attr(\'checked\', \'true\');

4、选中多个checkbox同时选中第1个和第2个的checkbox
$(\'input:checkbox\').slice(0,2).attr(\'checked\',\'true\');

5、根据Value值设置checkbox为选中值
$("input:checkbox[value=\'1\']").attr(\'checked\',\'true\');

6、设置某一个checkbox为选中值

选中checkbox:$(":checkbox").prop("checked", true);
取消选中:$(":checkbox").prop("checked", false);

参考:http://www.cnblogs.com/hs8888/archive/2016/05/23/5520511.html

发表于 2017-07-09 16:49  幽默是一种心情  阅读(1944)  评论(0编辑  收藏  举报
 

分类:

技术点:

相关文章:

  • 2021-12-30
  • 2021-12-02
  • 2021-11-14
  • 2021-08-08
  • 2022-01-07
  • 2022-03-05
  • 2021-11-06
猜你喜欢
  • 2022-01-10
  • 2021-11-03
  • 2022-01-07
  • 2021-10-14
  • 2021-12-10
  • 2021-12-26
  • 2021-10-05
相关资源
相似解决方案