zoukankan      html  css  js  c++  java
  • input复选框操作的部分高频率使用代码

    1. 获取单个checkbox选中项(三种写法):

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

    2. 获取多个checkbox选中项:

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

    3. 设置第一个checkbox 为选中值:

    1. $('input:checkbox:first').attr("checked",'checked'); 
    2. 或者 
    3. $('input:checkbox').eq(0).attr("checked",'true'); 

    4. 设置最后一个checkbox为选中值:

    1. $('input:radio:last').attr('checked', 'checked'); 
    2. 或者 
    3. $('input:radio:last').attr('checked', 'true');

    5. 根据索引值设置任意一个checkbox为选中值:

    1. $('input:checkbox).eq(索引值).attr('checked', 'true');索引值=0,1,2.... 
    2. 或者 
    3. $('input:radio').slice(1,2).attr('checked', 'true'); 

    6. 选中多个checkbox: 
    同时选中第1个和第2个的checkbox:

    1. $('input:radio').slice(0,2).attr('checked','true'); 

    7. 根据Value值设置checkbox为选中值:

    1. $("input:checkbox[value='1']").attr('checked','true');

    8. 删除Value=1的checkbox:

    1. $("input:checkbox[value='1']").remove();

    9. 删除第几个checkbox:

    1. $("input:checkbox").eq(索引值).remove();索引值=0,1,2.... 
    2. 如删除第3个checkbox: 
    3. $("input:checkbox").eq(2).remove();

    10.遍历checkbox:

    1. $('input:checkbox').each(function (index, domEle) { 
    2. //写入代码 
    3. });

    11.全部选中

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

    12.全部取消选择:

    1. $('input:checkbox').each(function () { 
    2.     $(this).attr('checked',false); 
    3. });
  • 相关阅读:
    rabbitmq报错:not_a_dets_file,"/var/lib/rabbitmq/mnesia/rabbit@Sfabrici-Demo01/recovery.dets"的解决办法
    ubuntu18上关闭默认的防火墙
    《GCD宣言》全文
    springboot日志配置
    springboot打jar包【我】
    MongoDB 4.2 用户管理
    【短道速滑四】Halcon的texture_laws算子自我研究
    Android集合之SparseArray、ArrayMap详解
    浅析微信支付:下载对账单和资金账单
    学习如修行
  • 原文地址:https://www.cnblogs.com/Lmey/p/7230497.html
Copyright © 2011-2022 走看看