支持ie8单选框与复选框自定义样式
来源:互联网 发布:淘宝跑腿服务靠谱吗 编辑:程序博客网 时间:2024/04/27 18:18
css 样式
/* wrapper divs 复选框与单选框样式 */
.custom-checkbox,.custom-radio{position:relative;}
/* input, label positioning 该样式控制checkbox */
.custom-checkbox input{position:absolute;left:2px;top:0px;margin:0;}
.custom-checkbox label{display:block;position:relative;padding-right:1em;line-height:1;padding:.7em 0 .5em 30px;margin:0 0 .3em;cursor:pointer;}
/* states */
.custom-checkbox label{background:url(checkbox.gif) no-repeat;}
.custom-radio label{background:url(radiobutton.gif) no-repeat;}
.custom-checkbox label,.custom-radio label{background-position:-10px -14px;}
.custom-checkbox label.hover,.custom-checkbox label.focus,.custom-radio label.hover,.custom-radio label.focus{background-position:-10px -114px;}
.custom-checkbox label.checked,.custom-radio label.checked{background-position:-10px -214px;}
.custom-checkbox label.checkedHover,.custom-checkbox label.checkedFocus{background-position:-10px -314px;}
.custom-checkbox label.focus,.custom-radio label.focus{outline:1px dotted #ccc;}
/* input, label positioning 该样式控制radio */
.custom-radio input{position:absolute;left:2px;top:2px;margin:0;}
.custom-radio label{display:block;position:relative;padding-right:1em;line-height:1;padding:.7em 0 .5em 30px;margin:0 0 .3em;cursor:pointer;}
js
jQuery.fn.customInput = function(){
return $(this).each(function(){
if($(this).is('[type=checkbox],[type=radio]')){
var input = $(this);
// 使用输入的ID得到相关的标签
var label = $('label[for='+input.attr('id')+']');
// 包裹在一个div输入+标签
input.add(label).wrapAll('<div class="custom-'+ input.attr('type') +'"></div>');
// 必要的浏览器不支持:hover伪类的标签
label.hover(
function(){ $(this).addClass('hover'); },
function(){ $(this).removeClass('hover'); }
);
//绑定自定义事件,触发它,绑定点击,焦点,模糊事件
input.bind('updateState', function(){
input.is(':checked') ? label.addClass('checked') : label.removeClass('checked checkedHover checkedFocus');
})
.trigger('updateState')
.click(function(){
$('input[name='+ $(this).attr('name') +']').trigger('updateState');
})
.focus(function(){
label.addClass('focus');
if(input.is(':checked')){ $(this).addClass('checkedFocus'); }
})
.blur(function(){ label.removeClass('focus checkedFocus'); });
}
});
};
jsp 页面写法
<td style="border: 0px"><input name="ghContent" id="ghbox6"
class="inputbox" type="radio" value="液压站" /> <label
for="ghbox6">液压站</label>
js 渲染 $('.inputbox').customInput(); //格式化复选框和单选框
点击打岔效果
jsp 页面写法
<td style="border: 0px"><input name="ghContent" id="ghbox6"
class="inputbox" type="radio" value="液压站" /> <label
for="ghbox6">液压站</label>
js 渲染 $('.inputbox').cusInput(); //格式化复选框和单选框
js 添加代码
jQuery.fn.cusInput = function(){
return $(this).each(function(){
if($(this).is('[type=checkbox]')){
var input = $(this);
// 使用输入的ID得到相关的标签
var label = $('label[for='+input.attr('id')+']');
// 包裹在一个div输入+标签
input.add(label).wrapAll('<div class="cus-'+ input.attr('type') +'"></div>');
// 必要的浏览器不支持:hover伪类的标签
label.hover(
function(){ $(this).addClass('hover'); },
function(){ $(this).removeClass('hover'); }
);
//绑定自定义事件,触发它,绑定点击,焦点,模糊事件
input.bind('updateState', function(){
input.is(':checked') ? label.addClass('checked') : label.removeClass('checked checkedHover checkedFocus');
})
.trigger('updateState')
.click(function(){
$('input[name='+ $(this).attr('name') +']').trigger('updateState');
})
.focus(function(){
label.addClass('focus');
if(input.is(':checked')){ $(this).addClass('checkedFocus'); }
})
.blur(function(){ label.removeClass('focus checkedFocus'); });
}
});
};
css添加代码
/** 差号显示 */
.cus-checkbox input{position:absolute;left:2px;top:0px;margin:0;}
.cus-checkbox label{display:block;position:relative;padding-right:1em;line-height:1;padding:.7em 0 .5em 30px;margin:0 0 .3em;cursor:pointer;}
.cus-checkbox label{background:url(checkbox_cha.gif) no-repeat;}
.cus-checkbox label{background-position:-10px -14px;}
.cus-checkbox label.hover,.cus-checkbox label.focus{background-position:-10px -114px;}
.cus-checkbox label.checked{background-position:-10px -214px;}
.cus-checkbox label.checkedHover,.cus-checkbox label.checkedFocus{background-position:-10px -314px;}
.cus-checkbox label.focus{outline:1px dotted #ccc;}
在我的资源中有写好的列子
- 支持ie8单选框与复选框自定义样式
- 自定义复选框样式
- 自定义复选框样式
- 自定义复选框样式
- 自定义复选框checkbox样式
- css修改单选框与复选框样式
- 自定义复选框,复选框样式修改,重写复选框
- 自定义复选框,复选框样式修改,重写复选框
- 复选框 单选框 样式
- 纯css3自定义复选框checkbox样式
- Jquery实现自定义复选框样式
- 自定义单选/复选框样式
- 单选 复选框自定义样式
- 最简单清晰的纯css实现的单选框radio复选框checkbox自定义样式
- Android开发-CheckedTextView复选框自定义样式-AndroidStudio
- bootstrap-table自定义复选框列的样式
- 单选框(复选框)按钮样式
- 单选框、复选框美观的样式
- eclipse集成weblogic开发环境的搭建
- 其他软件的使用问题记录
- Java中对于文件读取写入需要注意的事项
- 【mybatis】——简单程序示例
- 委托
- 支持ie8单选框与复选框自定义样式
- XSS学习总结
- Lombok 安装、入门 - 消除冗长的 java 代码
- 根据Type 变量动态创建可变内部类型的泛型
- 核电站问题(递推)
- java -- eclipse如何debug调试jdk源码
- 利用php截取字符去掉最后一个字符
- 强大的矩阵奇异值分解(SVD)及其应用
- 为何Redis要比Memcached好用