zoukankan      html  css  js  c++  java
  • 美化单选按钮

    在做项目中,经常会遇到提交,单选,复选。

    但是直接拿来用这些标签和样式,丑,太丑。那么有没有好的方法来处理这些表单元素呢?

    下面我举个例子,来处理单选按钮。

    中心思想:利用定位 把input按钮隐藏,然后给label加图片再用js控制(对于另类的效果需要用js控制,比如取消单选)

    html:

    1 <div id="box">
    2   <label for="radio-00" class="label_radio r_off">                     
    3     <input type="radio" name="communication"><span>12345</span>                 
    4    </label>
    5 </div>

    css:

    label {
        display: block;
        cursor: pointer;
        line-height: 16px;
        float: left;
    }
    .label_radio input {
        margin-right: 5px;
    }
    
    .label_radio {
        margin-right: 35px;
    }
    
    .label_radio {
        background: url(/img/radioBtn.png) no-repeat;
    }
    .label_radio {
        background-position: 0 -16px;
    }
    
    .label.r_on {
        background-position: 0 0;
    }
    .label_radio input {
        position: absolute;
        left: -9999px;
    }
    span{
        margin-left: 25px;
    }

    JavaScript:

     1 $("#box").on("click","input[type='radio']", function () {
     2     if($(this).parent().hasClass("r_on")){
     3       $(this).removeAttr("checked");
     4       $(this).parent().removeClass("r_on").addClass("r_off");
     5       return;
     6     }
     7     $("#box input[type='radio']").removeAttr("checked");
     8       $(this).attr("checked", "checked");
     9       $(this).parent().removeClass("r_off").addClass("r_on").siblings().removeClass("r_on").addClass("r_off");
    10 });
  • 相关阅读:
    webpack-配置
    webpack-配置
    webpack-配置
    Maximum Depth of Binary Tree
    Maximum Depth of Binary Tree
    Maximum Depth of Binary Tree
    Maximum Depth of Binary Tree
    网页中嵌入swf文件的几种方法
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
  • 原文地址:https://www.cnblogs.com/hanfei-cn/p/5359230.html
Copyright © 2011-2022 走看看