Bootstrap Switch事件处理程序无法正常工作

时间:2014-03-17 17:54:58

标签: javascript jquery ruby-on-rails twitter-bootstrap

我问了一个类似于这个here的问题,但现在我仍然坚持使用Bootstrap Switch的event handler。我想在交换机切换时打印出状态。目前,它仅在单击时切换状态,并且不会触发新事件。

以下是我的一些设置:

some.js

$(document).ready(function() {
  $("#famous-people-switch").bootstrapSwitch();

  $("#famous-people-switch").on("switchChange", function (e, data) {
    console.log(data.value);
  });
});

some.html.erb

<div class="col-md-6">
  <input id="famous-people-switch" type="checkbox" name="famous-people" checked>
  <h4>Famous People:</h4>
</div>

宝石

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

@import "bootstrap";
@import "bootstrap3-switch";

的application.js

//= require jquery
//= require jquery_ujs
//= require bootstrap
//= require bootstrap-switch
//
//= require_tree .

1 个答案:

答案 0 :(得分:0)

由于bootstrap-switch的版本,未触发事件。版本2不包含它们,并且gem目前仅支持版本2.我已经提交了一个pull请求来将gem更新为版本3(仍在开发中)。

分支w /版本3 https://github.com/tomprats/bootstrap-switch-rails/tree/allow-switch-v3

提取请求https://github.com/manuelvanrijn/bootstrap-switch-rails/pull/9

<强>用法

更新您的Gemfile以使用正确的分支:

gem "bootstrap-switch-rails", git: "git://github.com/tomprats/bootstrap-switch-rails, branch: "allow-switch-v3"

更新您的Application.js文件:

//= require bootstrap-switch3

更新您的Application.css文件:

*= require bootstrap-switch3

或Application.css.scss文件:

@import "bootstrap-switch3";