
bootstrapSwitch是一个很美观的切换控件,官网上对它的介绍也很详细。下面通过几个demo快速上手bootstrapSwitch。
如果你想了解更多关于bootstrap的知识,可以点击:bootstrap教程
首先,引用相应的js和css文件,把checkbox放进class为“switch”的div中,再在js中初始化
$('#mySwitch input').bootstrapSwitch();
就可以使用bootstrapSwitch了。
其中input有两个属性 data-on-text 和data-off-text,分别为切换时显示的文字,这里设置为YES和NO。代码如下:
html>
<meta>
<title>this is a bootstrap-switch test</title>
<script></script>
<script></script>
<script></script>
<link>
<link>
<script>
$(function(){
$('#mySwitch input').bootstrapSwitch();
})
</script>
<div>
<input>
</div>


也可以用js设置这两个属性,选中input元素后,通过方法bootstrapSwitch({attribute:value}) 修改属性。代码如下:
html>
<meta>
<title>this is a bootstrap-switch test</title>
<script></script>
<script></script>
<script></script>
<link>
<link>
<script>
$(function(){
$('#mySwitch input').bootstrapSwitch({
onText:'On',
offText:'Off'
});
})
</script><br><div>
<input>
</div>













