Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 引导开关不工作´;t事件_Javascript_Jquery_Twitter Bootstrap_Jquery Plugins_Jquery Events - Fatal编程技术网

Javascript 引导开关不工作´;t事件

Javascript 引导开关不工作´;t事件,javascript,jquery,twitter-bootstrap,jquery-plugins,jquery-events,Javascript,Jquery,Twitter Bootstrap,Jquery Plugins,Jquery Events,我有下面的html代码(可以正确地更改复选框的状态),当某些复选框的状态更改时,我需要运行一个警报 <div class="make-switch switch-small"> <input type="checkbox" checked="true" data-checkbox="VALUE1" class="alert-status"> </div> <div class="make-switch switch-small"> <

我有下面的html代码(可以正确地更改复选框的状态),当某些复选框的状态更改时,我需要运行一个警报

<div class="make-switch switch-small">
  <input type="checkbox" checked="true" data-checkbox="VALUE1" class="alert-status">
</div>
<div class="make-switch switch-small">
  <input type="checkbox" checked="true" data-checkbox="VALUE2" class="alert-status">
</div>
<div class="make-switch switch-small">
  <input type="checkbox" checked="true" data-checkbox="VALUE3" class="alert-status">
</div>
<div class="make-switch switch-small">
  <input type="checkbox" checked="true" data-checkbox="VALUE4" class="alert-status">
</div>
(二)

(三)

(四)

(五)

我在互联网上搜索过,我参考过一些例子,我使用过firebug,但我找不到捕捉事件的方法。有人能帮我吗

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


(我添加了probeProbe类和部分代码)

我认为您的代码应该正常工作


我的bootstrapSwitch 3也有同样的问题。所以,在尝试了很多变体都没有成功之后,我决定直接测试代码。毕竟,这是我的解决方案(至少在Chrome下,必须在其他浏览器包下测试)

有这个HTML

<div class="make-switch switch-small"> 
  <input type="checkbox" checked="true" data-checkbox="VALUE1" class="alert-status">
</div>

这个javascript非常适合我:

<script type="text/javascript">
   (function(){
       function value1Changed(event, state){
          var myNewState = state.value;
       }

       $('input[data-checkbox="VALUE1"]')
          .parent('.make-switch')
          .on('switch-change', value1Changed);
   });
</script>

(功能(){
功能值1已更改(事件、状态){
var myNewState=state.value;
}
$('input[data checkbox=“VALUE1”]”)
.parent(“.make开关”)
.on(“开关更改”,值1更改);
});
希望能有帮助

试试这个:

获取状态

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

$('.alert-status').on('switchChange.bootstrapSwitch', function (event, state) {
 if (state) {
    // true
 } else {
    // false
 }
   event.preventDefault();
});

我已将此代码粘贴到我的web中,但不起作用。我已启用firebug来检测可能的错误,但找不到任何错误,除了以下错误:错误:方法不退出状态!localhost/j/jquery-1.9.1.js第6行非常罕见,我无法让它工作。复选框将从“开”更改为“关”,但不会触发事件。非常感谢你。regardsIt很好奇,根据他的例子,我最终更改了我的文件“bootstrap switch.min.js”和“bootstrap switch.css”,并为我工作。。。谢谢@cococo先生!
/*$(".alert-status").click(function(event) {
          event.preventDefault();
          event.stopPropagation();
          alert($(this).attr('data-checkbox'));
});*/
<div class="make-switch switch-small">
  <input type="checkbox" checked="true" data-checkbox="VALUE1" class="alert-status">
</div>
<div class="make-switch switch-small">
  <input type="checkbox" checked="true" data-checkbox="VALUE2" class="alert-status">
</div>
<div class="make-switch switch-small">
  <input type="checkbox" checked="true" data-checkbox="VALUE3" class="alert-status">
</div>
<div class="make-switch switch-small">
  <input type="checkbox" checked="true" data-checkbox="VALUE4" class="alert-status">
</div>
$('.alert-status').bootstrapSwitch('state', true);


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

    alert($(this).data('checkbox'));
    //alert(event);
   // alert(state);
});
<div class="make-switch switch-small"> 
  <input type="checkbox" checked="true" data-checkbox="VALUE1" class="alert-status">
</div>
<script type="text/javascript">
   (function(){
       function value1Changed(event, state){
          var myNewState = state.value;
       }

       $('input[data-checkbox="VALUE1"]')
          .parent('.make-switch')
          .on('switch-change', value1Changed);
   });
</script>
$('.alert-status').bootstrapSwitch('state', true);
$('.alert-status').on('switchChange.bootstrapSwitch', function (event, state) {
 if (state) {
    // true
 } else {
    // false
 }
   event.preventDefault();
});