Bootstrap switch 开关事件处理

需要使用Bootstrap switch,实现通过、拒绝功能并且在开关至拒绝时,显示textarea框输入原因。

1、css引用
<link href="switch/css/bootstrap-switch.min.css" rel="stylesheet">

2、js引用
<script src="switch/js/bootstrap-switch.min.js"></script>

3、页面(使用modal打开,若须使用需引用对应的js和css)

<div class="modal inmodal" id="approve_modal" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content animated bounceInRight">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">
<span aria-hidden="true">&times;</span><span class="sr-only">关闭</span>
</button>
<h1 class="modal-title">月 报 审 批</h1>
<br>
<input type="checkbox" name="my-checkbox" id="my-checkbox">
</div>
<div class="modal-body">
<div class="form-group animated fadeIn" id="approve_input" style="display:none;">
<label style="font-size: 15px;">若不通过,请说明原因:</label>
<textarea id="approve_area" rows="5" placeholder="填写内容请控制在250字以内。" class="form-control" maxlength="250">
</textarea>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
<button type="button" class="btn btn-primary" id="submit">提交</button>
</div>
</div>
</div>
</div>

4、js页面

$("[name=‘my-checkbox‘]").bootstrapSwitch({
onText : "拒绝",
offText : "通过",
onColor : "danger",
offColor : "success",
size : "large",

//onSwitchChange方法监测switch开关状态

onSwitchChange : function() {

//.prop方法查看input的checked属性,即使查看其开关状态

var checkedOfAll=$("#my-checkbox").prop("checked");

//false、true对应input的checked属性,显示和隐藏输入框

if (checkedOfAll==false){
$(‘#approve_input‘).hide()
}
else {
$(‘#approve_input‘).show()
}
}
});
$(‘#submit‘).click(function () {
var checkedOfAll=$("#my-checkbox").prop("checked");
var checkinfo=$(‘#approve_area‘).val();
alert(checkedOfAll+checkinfo)
})

原文地址:http://blog.51cto.com/bilibili/2133343

时间: 2024-08-29 19:35:11

Bootstrap switch 开关事件处理的相关文章

前端插件之Bootstrap Switch 选择框开关控制

简介 Bootstrap Switch是一款轻量级插件,可以给选择框设置类似于开关的样式 它是依赖于Bootstrap的一款插件 下载 下载地址 在线引用 导入 因为它是依赖于Bootstrap的一款插件,所以,在引入之前要先引入Bootstrap样式 <link rel="stylesheet" type="text/css" href="/static/plugin/bootstrap/css/bootstrap.min.css">

微信小程序组件解读和分析:十五、switch 开关选择器

switch 开关选择器组件说明: switch,开关选择器.只能选择或者不选.这种属于表单控件或者查询条件控件. switch 开关选择器示例代码运行效果如下: 下面是WXML代码: [XML] 纯文本查看 复制代码 ? 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 <view class="secti

CSS做一个Switch开关

本文为博主原创,转载请注明出处. Switch开关: 根据需求可知,Switch开关只有两种选择,true或false.所以我们想到HTML的checkbox控件,用它来做. <input id="switch" type="checkbox" class="switch" /> 但是在浏览器中,checkbox是有固定形状的(对勾),所以我们并不能直接修改checkbox的样式. 那我们该修改一个什么东西的样式变成开关呢?所以我们联

bootstrap switch功能

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'

使用css3 制作switch开关

本片文章将简单的采用input[type=checkbox]跟css3来实现switch开关的效果,效果图如下: html代码: <div class="bg_con"> <input id="checkSwitch" type="checkbox" checked="true" class="switch" /> <label for="checkSwitch&qu

mui switch 开关js控制打开 &amp; Cannot read property &#39;toggle&#39; of null

//打开开关 mui('#mySwitch').switch().toggle(); //小开关打开异常的情况解决办法$(".mui-switch-handle").attr("style",""); 发生Cannot read property 'toggle' of null是因为,执行打开开关需要等页面加载完在执行 写个定时器就可以了 setTimeout(function(){ mui('#mySwitch').switch().togg

fastadmin switch开关失效

原文地址:https://www.cnblogs.com/wen-zi/p/9965800.html switch  开关失效无法切换,可以关闭,无法开启. 发现问题点 require-table.js 中toggle value的数据类型不是 number 导致 (value ? no : yes )判断总为no: 前面将value 强制转换为number类型即可 2.修改data-id 原文地址:https://www.cnblogs.com/bisonkeji/p/11416556.htm

使用jQuery获取Bootstrap Switch的值

$('#switcher').bootstrapSwitch('state'); // true || false $('#switcher').bootstrapSwitch('toggleState'); $('#switcher').bootstrapSwitch('setState', false); // true || false 访问这个链接获取更多的方法 博文参考自:How to get twitter bootstrap toggle switch values using j

自定义switch开关控件,实现点击和滑动效果

效果图 1. xml布局中 <com.etoury.etoury.ui.view.SlideSwitch android:id="@+id/slideSwitch3" android:layout_width="wrap_content" android:layout_height="wrap_content" /> 2. SlideSwitch.java package com.etoury.etoury.ui.view; impo