打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Bootstrap 开关(switch)控件

Bootstrap 开关(switch)控件是一个很美(对,只能这一个字)的开关按钮组件。

效果


材料准备

Bootstrap 开关(switch)控

开始

<link type="text/css" rel="stylesheet" href="${ctx}/components/switch/css/bootstrap3/bootstrap-switch.min.css" /><script type="text/javascript" src="${ctx}/components/switch/js/bootstrap-switch.min.js"></script>
  • 1
  • 2
  • 3
  • 1
  • 2
  • 3

引入这两个文件,至于bootstrap的css和js,肯定是要的!

<div class="switch" onColor="success" offColor="warning" onText="参与" offText="不参与" labelText="大宗交易">    <input type="checkbox" checked /></div>
  • 1
  • 2
  • 3
  • 1
  • 2
  • 3


1. div完全是为了给checkbox添加式样。
2. input就很简单了,就是普通的标签。

启动

$("div[class='switch']").each(function() {    $this = $(this);    var onColor = $this.attr("onColor");    var offColor = $this.attr("offColor");    var onText = $this.attr("onText");    var offText = $this.attr("offText");    var labelText = $this.attr("labelText");    var $switch_input = $(" :only-child", $this);    $switch_input.bootstrapSwitch({        onColor : onColor,        offColor : offColor,        onText : onText,        offText : offText,        labelText : labelText    });});
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17


1. 通过jQuery获取所有的switch div,从而获取其属性onColor 、offColor 等等
2. 紧接着,获取div包含的子元素input。
3. 通过bootstrapSwitch方法对input进行加载。

笑对现实的无奈,不能后退的时候,不再傍徨的时候,永远向前 路一直都在──陈奕迅《路一直都在》
本文出自:【沉默王二的博客

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
值得分享的Bootstrap Ace模板实现菜单和Tab页效果
uaucms 开发日志: 基于bootstrap的ajax加载和可url定位tab插件制作
基于Metronic的Bootstrap开发框架经验总结(10)
Elasticsearch 索引生命周期管理
netty 学习笔记二:服务端、客户端启动流程
bootstrap表格 行编辑状态_详解bootstrap table双击可编辑、添加、删除行
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服