bootstrap的icheck插件使用

由于我们在项目开发时会经常用到单选框和复选框,并且众所周知其样式不易修改,它们的原有样式不能满足我们项目美观所需,所以这个时候icheck插件就能帮到我们不少呢,下来我就来说说icheck插件的使用:

iCheck

特色:

1、在不同浏览器(包括ie6+)和设备上都有相同的表现 — 包括 桌面和移动设备

2、支持触摸设备 — iOSAndroid、BlackBerry、Windows Phone等系统

4、方便定制 — 用HTML 和 CSS 即可为其设置样式 (多套皮肤)

5、体积小巧 — gzip压缩后只有1 kb

6、25 种参数 用来定制复选框(checkbox)和单选按钮(radio button)

7、8 个回调事件 用来监听输入框的状态

8、7个方法 用来通过编程方式控制输入框的状态

9、能够将输入框的状态变化同步回原始输入框中, 支持所有选择器

iCheck插件表单美化效果图:

iCheck插件表单美化效果图

iCheck初始化:

首先,引入jQuery库文件

其次,引入jquery.icheck.js插件文件

(如果要引入相关皮肤,则需引入:相关主题颜色.css文件)

iCheck皮肤:

Black — minimal.css //黑色

Red — red.css //红色

Green — green.css //绿色

Blue — blue.css //蓝色

Aero — aero.css //win7中的那种玻璃效果

Grey — grey.css //银灰色

Orange — orange.css //橙色

Yellow — yellow.css //黄色

Pink — pink.css //粉红色

Purple — purple.css //紫色

(请在skins包里自行下载这些皮肤包)

iCheck使用方法:

$('input').iCheck('check');   //将输入框的状态设置为checked 
$('input').iCheck('uncheck'); //移除 checked 状态 
$('input').iCheck('toggle');  //toggle checked state 
$('input').iCheck('disable'); //将输入框的状态设置为 disabled 
$('input').iCheck('enable');  //移除 disabled 状态 
$('input').iCheck('update');  //apply input changes, which were done outside the plugin 
$('input').iCheck('destroy'); //移除iCheck样式 
 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

调用iCheck时,只需要将修改了默认值的参数列出来即可:

//基础使用方法 
$('input').iCheck({ 
  labelHover : false, 
  cursor : true, 
  checkboxClass : 'icheckbox_square-blue', 
  radioClass : 'iradio_square-blue', 
  increaseArea : '20%' 
}); 
 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

下面是参数列表及其默认值:

{ 
 handle: '', 
 checkboxClass: 'icheckbox', 
 radioClass: 'iradio', 
 checkedClass: 'checked', 
 checkedCheckboxClass: '', 
 checkedRadioClass: '', 
 uncheckedClass: '', 
 uncheckedCheckboxClass: '', 
 uncheckedRadioClass: '', 
 disabledClass: 'disabled', 
 disabledCheckboxClass: '', 
 disabledRadioClass: '', 
 enabledClass: '', 
 enabledCheckboxClass: '', 
 enabledRadioClass: '', 
 hoverClass: 'hover', 
 focusClass: 'focus', 
 activeClass: 'active', 
 labelHover: true, 
 labelHoverClass: 'hover', 
 increaseArea: '', 
 cursor: false, 
 inheritClass: false, 
 inheritID: false, 
 insert: '' 
} 
 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27

iCheck回调事件 
iCheck支持所有选择器(selectors),并且只针对复选框checkbox和单选radio按钮起作用 
iCheck提供了大量回调事件,都可以用来监听change事件 
事件名称 : 使用时机 
ifClicked : 用户点击了自定义的输入框或与其相关联的label 
ifChanged : 输入框的 checked 或 disabled 状态改变了 
ifChecked :输入框的状态变为 checked 
ifUnchecked :checked 状态被移除 
ifDisabled : 输入框状态变为 disabled 
ifEnabled : disabled 状态被移除 
ifCreated : 输入框被应用了iCheck样式 
ifDestroyed: iCheck样式被移除 
使用on()方法绑定事件:

$('input').on('ifChecked', function(event){ //ifCreated 事件应该在插件初始化之前绑定 
  alert(event.type + ' callback'); 
}); 
 
 
  • 1
  • 2
  • 3
  • 1
  • 2
  • 3

bootstrap iCheck中的radio和checkbox的大小可以调整吗?

.icheckbox_square-blue, .iradio_square-blue { 
  display: block; 
  margin: 0; 
  padding: 0; 
  width: 22px; 
  height: 22px; 
  background: url(blue.png) no-repeat; 
  border: none; 
  cursor: pointer; 
} 
 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

如果要调整icheck的radio或checkbox样式,通过上面的css修改width和height,同时修改blue.png图片对应的尺寸。

icheck插件下载请戳这里

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值