radio美化插件

效果图:

css:
<pre>
<code>
.myForm{width:500px;height: 500px;border: 1px solid #cecece;margin: 50px;}
.myForm form{margin: 100px;}
.myForm input{float: left;margin: 20px;}
.myForm b{float: left;display: inline-block;width: 22px;height: 22px;background: url(images/radioOff.png) no-repeat center top;}//图片根据自己的需求修改
.myForm .bg{background: url(images/radioOn.png) no-repeat center top;}
.myForm input{display: none;}
.myForm label{float: left;line-height: 22px;margin: 0 10px;}
</code>
</pre>

html:
<pre>
<code>
<div class="myForm">
<form action="">
<p><label for="">男</label><input type="radio" name="radio" class="myRadio"></p>
<p><label for="">女</label><input type="radio" name="radio" class="myRadio"></p>
</form>
</div>
</code>
</pre>

js插件代码:可以自己新建一个js文件把下面代码放进去。

<pre><code>$(function(){
init = function(options){
var op = $.extend({
$radioClass: '',
$bHtml: '',
$bg: ''
},options);
var b = $(op.$bHtml).insertBefore(op.$radioClass);
b.on('click',function(){
$(this).next(op.$radioClass).click();
if($(this).next(op.$radioClass).attr('checked') == 'checked'){
$(this).addClass(op.$bg);
$(this).parent().siblings().find($(b)).removeClass(op.$bg);
}
})
}
})</code></pre>

自定义radio样式js代码:
<pre><code>$(function(){
init({
$radioClass: $('input[class="myRadio"]'),
$bHtml: "<b></b>",
$bg: 'bg'
})
})</code></pre>

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 173,954评论 25 709
  • 实话生活 体悟人生 今天是2017年2月3日 天气晴天 温度13-19度 今天早上五点多起床 起来了以后 先按柔腹...
    木风恒阅读 156评论 0 0
  • 我搁浅的,都是最美的墓志铭——题记 四月的天空,我望不见一片云朵,温柔的阳光从不可相望的角度泄下来,那般从容却刺痛...
    痞墨阅读 467评论 0 3
  • 听了一个讲座,题目是“我们为什么要在年轻的时候多旅行”。 年轻的时候有时间没有钱,工作的时候有钱没有时间。人生就是...
    scmsuki阅读 121评论 0 0
  • 10月11日,2017中国--东盟博览会旅游展在广西桂林市国际会展中心开馆。这次展会超过六十个国家和地区参加,印度...
    爱吃的胖头鱼阅读 479评论 0 0