zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    Git 之 git原理简介
    Django 之 富文本编辑器-tinymce
    Django 之 Ajax
    Django 之 分页
    Django 之 用redis存储session
    Django 之 自定义中间件
    python 之 多线程、多进程代码
    反转字符串
    青蛙跳台阶
    pandas 之 concat
  • 原文地址:https://www.cnblogs.com/weimingxin/p/7141966.html
Copyright © 2011-2022 走看看