码迷,mamicode.com
首页 > 其他好文 > 详细

bootstrap switch功能

时间:2015-02-27 11:47:10      阅读:639      评论:0      收藏:0      [点我收藏+]

标签:

bootstrap switch是一个按钮开关,点击时获取其状态可通过以下代码:

1 <input id="email_switch_state" type="checkbox">

 

 1 $(‘#email_switch_state‘).on({        
 2         ‘switchChange.bootstrapSwitch‘: function(event, state) {
 3             if (state == true)
 4             {
 5                 $(‘#text‘).html(‘OK‘);
 6             }
 7             else
 8             {
 9                 $(‘#text‘).html(‘NO‘);
10             }
11         }
12 });

 

Additional Methods

NameDescription
toggleState Toggle the switch state
toggleAnimate Toggle the animate option
toggleDisabled Toggle the disabled state
toggleReadonly Toggle the readonly state
toggleIndeterminate Toggle the indeterminate state
toggleInverse Toggle the inverse option
destroy Destroy the instance of Bootstrap Switch

Options

NameAttributeTypeDescriptionValuesDefault
state checked Boolean The checkbox state true, false true
size data-size String The checkbox size null, ‘mini‘, ‘small‘, ‘normal‘, ‘large‘ null
animate data-animate Boolean Animate the switch true, false true
disabled disabled Boolean Disable state true, false false
readonly readonly Boolean Readonly state true, false false
indeterminate data-indeterminate Boolean Indeterminate state true, false false
inverse data-inverse Boolean Inverse switch direction true, false false
radioAllOff data-radio-all-off Boolean Allow this radio button to be unchecked by the user true, false false
onColor data-on-color String Color of the left side of the switch ‘primary‘, ‘info‘, ‘success‘, ‘warning‘, ‘danger‘, ‘default‘ ‘primary‘
offColor data-off-color String Color of the right side of the switch ‘primary‘, ‘info‘, ‘success‘, ‘warning‘, ‘danger‘, ‘default‘ ‘default‘
onText data-on-text String Text of the left side of the switch String ‘ON‘
offText data-off-text String Text of the right side of the switch String ‘OFF‘
labelText data-label-text String Text of the center handle of the switch String ‘&nbsp;‘
handleWidth data-handle-width String | Number Width of the left and right sides in pixels ‘auto‘ or Number ‘auto‘
labelWidth data-label-width String | Number Width of the center handle in pixels ‘auto‘ or Number ‘auto‘
baseClass data-base-class String Global class prefix String ‘bootstrap-switch‘
wrapperClass data-wrapper-class String | Array Container element class(es) String | Array ‘wrapper‘
onInit   Function Callback function to execute on initialization Function
function(event, state) {}
onSwitchChange   Function Callback function to execute on switch state change Function
function(event, state) {}

 

$.fn.bootstrapSwitch.defaults.size = ‘large‘; 
$.fn.bootstrapSwitch.defaults.onColor = ‘success‘;
$(‘#toggle-state-switch‘).bootstrapSwitch(‘state‘);

 

bootstrap switch功能

标签:

原文地址:http://www.cnblogs.com/linguoguo/p/4302810.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!