引导开关检查事件? [英] Bootstrap switch checked event?

查看:260
本文介绍了引导开关检查事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对复选框已选中的活动使用此代码,但不起作用。

I use this codes for checkbox checked event but it does not work.

css

<link href="assets/plugins/bootstrap-switch/static/stylesheets/bootstrap-switch-metro.css" rel="stylesheet" type="text/css" />

html

<div class="switch switch-mini" data-on-label="<i class='icon-sun icon-white'></i>" data-off-label="<i class='icon-sun muted'></i>">
    <input id="swWeather" type="checkbox" class="toggle" onclick="toggleWeather()" />
</div>

js

<script src="assets/plugins/bootstrap-switch/static/js/bootstrap-switch.js" type="text/javascript"></script>

如果我使用这种方式,只是视觉风格很好,但它不会触发 toggleWeather()函数,但是如果我删除 bootstrap-switch.js ,所有的视觉样式都被删除,

If I use this way, just visual style work well but it does not trigger toggleWeather() function, but if I remove bootstrap-switch.js, all visual styles are removed and looks standard as standard checkbox, although it works very well.

如何更改复选框已选中的状态请使用bootstrap-switch点击它。

How can I change checkbox checked status click it with bootstrap-switch?

toggleWeather(){

if(document.getElementById('swWeather')); //切换代码:

Here my toggleweather code:

function toggleWeather() {

            if (document.getElementById('swWeather').checked)

            { weatherLayer.setMap(map); }

            else

            { weatherLayer.setMap(null); }

            if (document.getElementById('swCloud').checked)

            { cloudLayer.setMap(map); }

            else

            { cloudLayer.setMap(null); }
        }

我用这个主题使用这些开关:
http://www.keenthemes.com/preview/metronic_admin/form_component.html#myModal

by the way I use these switches with this theme: http://www.keenthemes.com/preview/metronic_admin/form_component.html#myModal

这不是好的例子,但是像
http://jsfiddle.net / UHkN6 /

It is not good example but like that http://jsfiddle.net/UHkN6/

推荐答案

对于bootstrap-switch 3.0发布候选项, b
$ b

For bootstrap-switch 3.0 release candidate the event given as example:

$('#switch-change').on('switchChange', function (e, data) {}); 

在官方网页上没有被解雇。

on the official page doesn't get fired.

改为使用:

$('#switch-change').on('switchChange.bootstrapSwitch', function (event, state) {}); 

其中 state 参数是复选框

这可能会在稳定版本中修复。

This will probably be fixed in a stable release.

这篇关于引导开关检查事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆