小编use*_*250的帖子

Bootstrap开关检查事件?

我使用此代码进行复选框检查事件,但它不起作用.

CSS

<link href="assets/plugins/bootstrap-switch/static/stylesheets/bootstrap-switch-metro.css" rel="stylesheet" type="text/css" />
Run Code Online (Sandbox Code Playgroud)

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>
Run Code Online (Sandbox Code Playgroud)

JS

<script src="assets/plugins/bootstrap-switch/static/js/bootstrap-switch.js" type="text/javascript"></script>
Run Code Online (Sandbox Code Playgroud)

如果我使用这种方式,只是视觉样式工作良好,但它不会触发toggleWeather()功能,但如果我删除bootstrap-switch.js,所有视觉样式都被删除,看起来标准为标准复选框,虽然它工作得很好.

如何更改复选框选中状态使用bootstrap-switch单击它?

在这里我的toggleweather代码:

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); }
        }
Run Code Online (Sandbox Code Playgroud)

顺便说一句,我使用这个主题的开关:http: //www.keenthemes.com/preview/metronic_admin/form_component.html#myModal

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

javascript css checkbox jquery twitter-bootstrap

32
推荐指数
5
解决办法
8万
查看次数

标签 统计

checkbox ×1

css ×1

javascript ×1

jquery ×1

twitter-bootstrap ×1