• 修改checkbox的默认样式


    html 

    <input type="checkbox"/>

    css

    span.myCheck​{    ​​
    •display: inline-block;
    
          13px;
    
         height: 13px;
    
        background-image:url("../images/radio.png");
    
        background-repeat: no-repeat;
    
       cursor: pointer;
    
       background-position: 0px -30px;
    
       margin-right: 3px;
    
       text-align: center;
    
    ​}​
    
    ​span.myCheck.mySelect​{
    
        ​background-position: 0px -45px;
    
    ​}​

    js

         $(function() {
    
           //默认的样式 包裹
    
           $.each($('input[type="checkbox"]'),function(i,n){
    
              $(this).wrap("");
    
                if($(n).attr('checked')){
    
                 $(n).parent('.myCheck').first().addClass('mySelect');
    
                 }
    
             });
    
           //点击后
    
           $('.myCheck').click(function(){
    
            //调用点击事件
    
              $(this).children('input[type="checkbox"]')[0].click(); 
    
            //不可用时
    
            if($(this).children('input[type="checkbox"]').attr("disabled")=="disabled"){
    
                return false;
    
             }      
    
            if($(this).children('input[type="checkbox"]').attr('checked')){
    
               $(this).children('input[type="checkbox"]').removeAttr("checked");
    
               $(this).removeClass('mySelect');
    
            }else{
    
               $(this).children('input[type="checkbox"]').attr('checked','checked');
    
              $(this).addClass('mySelect');
    
            }
    
            //点击全选
    
             按情况处理
    
            });   
    
       });

    实现效果

     

     

     
  • 相关阅读:
    UVA 120 Stacks of Flapjacks
    HDU 4869 Turn the pokers
    HDU 4882 ZCC Loves Codefires
    HDU 4864 Task
    HDU 4861 Couple doubi
    UVA 1600 Patrol Robot
    UVA 712 S-Trees
    2014/4/6长沙多校第六次(浙大校赛)
    UVA10905 思维考察
    HDU1498 枚举+二分图类棋盘问题(最大匹配)
  • 原文地址:https://www.cnblogs.com/sliuie/p/5091155.html
Copyright © 2020-2023  润新知