javascript – Bootstrap-switch不是事件

前端之家收集整理的这篇文章主要介绍了javascript – Bootstrap-switch不是事件前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
@H_301_1@我有以下HTML代码(正常工作正在更改复选框的状态),我需要在更改某个复选框的状态时运行警报.

@H_301_1@

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">
@H_301_1@我尝试了以下组合,但我无法执行例程:

@H_301_1@1)

@H_301_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);
});
@H_301_1@2)

@H_301_1@

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

@H_301_1@

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

@H_301_1@

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

@H_301_1@

/*$(".alert-status").click(function(event) {
          event.preventDefault();
          event.stopPropagation();
          alert($(this).attr('data-checkBox'));
});*/
@H_301_1@我在互联网上搜索过,我查过了一些例子,我用过萤火虫,我发现无法捕捉到这个事件.谁能帮我?

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

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

@H_301_1@谢谢.

@H_301_1@最好的祝福

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

@H_301_1@

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">
@H_301_1@JavaScript的:

@H_301_1@

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


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

    alert($(this).data('checkBox'));
    //alert(event);
   // alert(state);
});

猜你在找的jQuery相关文章