Bootstrap Switch事件处理程序无法正常工作 [英] Bootstrap Switch Event Handler not working
问题描述
我问了一个与此类似的问题此处但现在我一直坚持使用Bootstrap Switch的事件处理程序。我想在交换机切换时打印出状态。目前它只在点击时切换状态,并且不会触发新事件。
I asked a question similar to this one here but now I'm stuck on using Bootstrap Switch's event handler. I want to just print out the state when the switch gets toggled. Currently it only switches the state when clicked and does not trigger the new event.
以下是我的一些设置:
$(document).ready(function() {
$("#famous-people-switch").bootstrapSwitch();
$("#famous-people-switch").on("switchChange", function (e, data) {
console.log(data.value);
});
});
some.html.erb
some.html.erb
<div class="col-md-6">
<input id="famous-people-switch" type="checkbox" name="famous-people" checked>
<h4>Famous People:</h4>
</div>
宝石
Gems
Using sass (3.3.2)
Using bootstrap-sass (3.1.1.0)
Using bootstrap-switch-rails (2.0.2)
Using jquery-rails (3.1.0)
Using sass-rails (4.0.1)
Application.css.scss
Application.css.scss
@import "bootstrap";
@import "bootstrap3-switch";
Application.js
Application.js
//= require jquery
//= require jquery_ujs
//= require bootstrap
//= require bootstrap-switch
//
//= require_tree .
推荐答案
由于版本的原因,事件未被触发引导开关。版本2不包含它们,并且gem目前仅支持版本2.我已提交拉取请求以将gem更新为版本3(仍在开发中)。
The event is not being triggered due to the version of bootstrap-switch. Version 2 does not include them and the gem currently only supports Version 2. I've submitted a pull request to update the gem to version 3 (still being developed).
分支w /版本3 : https: //github.com/tomprats/bootstrap-switch-rails/tree/allow-switch-v3
提取请求: https://github.com/manuelvanrijn/bootstrap-switch-rails/pull/9
用法
更新您的Gemfile以使用正确的分支:
Update your Gemfile to use the correct branch:
gem "bootstrap-switch-rails", git: "git://github.com/tomprats/bootstrap-switch-rails, branch: "allow-switch-v3"
更新你的Application.js文件:
Update your Application.js file:
//= require bootstrap-switch3
更新您的Application.css文件:
Update your Application.css file:
*= require bootstrap-switch3
或Application.css.scss文件:
Or Application.css.scss file:
@import "bootstrap-switch3";
这篇关于Bootstrap Switch事件处理程序无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!