【问题标题】:Laravel 6 with Bootstrap Toggle and toggle-event do not work with jQuery带有 Bootstrap 切换和切换事件的 Laravel 6 不适用于 jQuery
【发布时间】:2020-03-15 17:10:20
【问题描述】:

我遵循了整个 Bootstrap Toggle 文档,但在我的 Laravel 6 刀片文件中,该操作仍然无法在 jQuery 中运行。

从 HTML 中删除 data-toggle="toggle",该操作有效。

看起来有些东西正在忽略或覆盖数据切换事件。

我已经尝试使用.toggle-event 来声明class="toggle-event",但也没有成功。

$(document).ready(function() {
  $('#toggle-event').change(function() {
    console.log(Date());
  });
})
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/gh/gitbrent/bootstrap4-toggle@3.6.1/js/bootstrap4-toggle.min.js"></script>
<link href="https://cdn.jsdelivr.net/gh/gitbrent/bootstrap4-toggle@3.6.1/css/bootstrap4-toggle.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>


<input id="toggle-event" type="checkbox" data-toggle="toggle" data-size="small" data-on="Enabled" data-off="Disabled" data-onstyle="success" data-offstyle="danger" data-id="1">

【问题讨论】:

    标签: jquery bootstrap-4 toggle laravel-6


    【解决方案1】:

    我放弃了在 Laravel 6 中使用 Bootstrap Toggle,然后我使用 Switchery 尝试了相同的结果,并且在第一次尝试中就成功了!

    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/switchery/0.8.2/switchery.min.css">
    <script src="https://cdnjs.cloudflare.com/ajax/libs/switchery/0.8.2/switchery.min.js"></script>
    

    还有这个:

    <input name="status" type="checkbox" class="js-switch" data-id="{{$system->id}}" {{ $system->active ? 'checked' : '' }}>
    

    【讨论】:

      猜你喜欢
      • 2015-09-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-27
      • 1970-01-01
      • 2020-09-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多