On/Off 带启动框确认的 FlipSwitch 按钮

On/Off FlipSwitch button with bootbox confirm

我正在使用 On/Off FlipSwitch 切换状态,但在切换之前需要用户确认。我正在使用 this example. Given example working fine with normal js confirmbut I want to use bootbox.js confirm. I am trying here 但它并非不起作用。

谁能帮帮我。

试试这个代码 (demo)

$('.onoffswitch').on('click', '.onoffswitch-label', function(event) {
  var checkbox = $(this).prev()[0];
  event.preventDefault();
  bootbox.confirm({
    message: "Are you sure ?",
    closeButton: false,
    callback: function(result) {
      if (result) {
        checkbox.checked = !checkbox.checked;
        $(checkbox).change();
      }
    }
  });
});