• 修改radio的默认样式


    最近在进行页面改版的时候越到了需要修改radio的样式的问题,发现纯的css很难的改变浏览器的默认样式。最后选择了span+js来实现

    html:

    <input type="radio"/>

    css:

    span.radioType {​
     
      display: inline-block;
    
       13px;
    
      height: 13px;
    
      background-image:url("../images/radio.png");
    
      background-repeat: no-repeat;
    
      cursor: pointer;
    
      margin-right: 3px;
    
    }​
    
    span.radioType.backg {
    
    ​    background-position: 0px -15px;
    
    }​

    ​js

         $(function() {
    
         //包裹
    
         $.each($('input[type="radio"]'),function(i,n){
    
              $(this).wrap("");
    
                if($(n).attr('checked')){
    
                 $(n).parent('.radioType').first().addClass('backg');
    
                 }
    
             });
    
           //点击后
    
           $('.radioType').click(function(){
    
                 //调用点击事件
    
                  $(this).children('input[type="radio"]')[0].click();
    
                 //移除所以name相同的  
    
                 var name=$(this).children('input[type="radio"]').attr("name");
    
            $('.radioType').each(function(){
    
                if($(this).children('input[type="radio"]').attr("name")==name){
    
                 $(this).children('input[type="radio"]').removeAttr('checked');   
    
                 $(this).removeClass('backg');
    
             }
    
            })
    
                $(this).children('input[type="radio"]').attr('checked','checked');
    
                $(this).addClass('backg');
    
       });
    
         });

    实现效果

    点我查看效果

  • 相关阅读:
    python字典类型
    python集合类型
    python元组类型
    python列表类型
    Python中的序列操作
    python字符串格式化输出
    python可变对象和不可变对象的解释
    Python数值类型
    Python循环结构用法
    python if条件判断语句
  • 原文地址:https://www.cnblogs.com/sliuie/p/5091142.html
Copyright © 2020-2023  润新知