javascript – Bootstrap-switch不是事件

前端之家收集整理的这篇文章主要介绍了javascript – Bootstrap-switch不是事件前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我有以下HTML代码(正常工作正在更改复选框的状态),我需要在更改某个复选框的状态时运行警报.

Box" checked="true" data-checkBox="VALUE1" class="alert-status"> Box" checked="true" data-checkBox="VALUE2" class="alert-status"> Box" checked="true" data-checkBox="VALUE3" class="alert-status"> Box" checked="true" data-checkBox="VALUE4" class="alert-status">

我尝试了以下组合,但我无法执行例程:

1)

$('.make-switch.input[type="checkBox"]').on('switchChange.bootstrapSwitch',function(event,state) {
          console.log(this); // DOM element
          console.log(event); // jQuery event
          console.log(state); // true | false
          alert(this);
});

2)

$('input[type="checkBox"]').on('switchChange.bootstrapSwitch',state) {
          console.log(this); // DOM element
          console.log(event); // jQuery event
          console.log(state); // true | false
          alert(this);
});

3)

$('.alert-status').on('switchChange.bootstrapSwitch',state) {
          console.log(this); // DOM element
          console.log(event); // jQuery event
          console.log(state); // true | false
          alert(this);
});

4)

$('.alert-status').on('switchChange',state) {
          console.log(this); // DOM element
          console.log(event); // jQuery event
          console.log(state); // true | false
          alert(this);
});

5)

/*$(".alert-status").click(function(event) {
          event.preventDefault();
          event.stopPropagation();
          alert($(this).attr('data-checkBox'));
});*/

我在互联网上搜索过,我查过了一些例子,我用过萤火虫,我发现无法捕捉到这个事件.谁能帮我?

我找到了这个例子,并在这个环境中进行了修改和工作,而不是在我的网站上:

http://jsfiddle.net/sumw4/13/(我添加了probeProbe类和部分代码)

谢谢.

最好的祝福

最佳答案
我认为你的代码应该工作http://jsfiddle.net/PNU45/

Box" checked="true" data-checkBox="VALUE1" class="alert-status"> Box" checked="true" data-checkBox="VALUE2" class="alert-status"> Box" checked="true" data-checkBox="VALUE3" class="alert-status"> Box" checked="true" data-checkBox="VALUE4" class="alert-status">

JavaScript的:

$('.alert-status').bootstrapSwitch('state',true);


$('.alert-status').on('switchChange.bootstrapSwitch',function (event,state) {

    alert($(this).data('checkBox'));
    //alert(event);
   // alert(state);
});
原文链接:https://www.f2er.com/jquery/428757.html

猜你在找的jQuery相关文章