0

我正在尝试在我的 rails 项目中使用引导类将复选框设置为开关,但我不知道为什么它不起作用。可能是语法错误(虽然我尝试了很多组合) 有没有人遇到过这个问题?

<div class="checkbox form-check form-switch">
     <%= sched.check_box :closed, {checked: sched.object.persisted?}, false, true, class: 'form-check-input', id: 'flexSwitchCheckDefault' %>  <%= sched.label :closed, day[:label], class: 'form-check-label', for: 'flexSwitchCheckDefault' %>
</div>

如果有帮助,该应用程序目前在Heroku上

4

2 回答 2

0

在此处输入图像描述 Bootstrap 未正确安装或集成到您的应用程序中

<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta3/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta3/dist/js/bootstrap.bundle.min.js"></script>
<div class="form-check form-switch">
  <input class="form-check-input" type="checkbox" id="flexSwitchCheckChecked" checked>
  <label class="form-check-label" for="flexSwitchCheckChecked">Checked switch checkbox input</label>
</div>

这是放置在 HTML 页面中的测试代码,此代码在 switch 中转换意味着引导程序集成成功

链接:https ://getbootstrap.com/docs/5.0/forms/checks-radios/

于 2021-04-01T17:37:43.337 回答
0

如果您使用的是 Bootstrap v4(已标记),那么您的类名错误。

尝试这个:

<div class="custom-control custom-switch">
     <%= sched.check_box :closed, {checked: sched.object.persisted?}, false, true, class: 'custom-control-input', id: 'flexSwitchCheckDefault' %>  
     <%= sched.label :closed, day[:label], class: 'custom-control-label', for: 'flexSwitchCheckDefault' %>
</div>

https://getbootstrap.com/docs/4.6/components/forms/#switches

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/css/bootstrap.min.css" integrity="sha384-B0vP5xmATw1+K9KRQjQERJvTumQW0nPEzvF6L/Z6nronJ3oUOFUFpCjEUQouq2+l" crossorigin="anonymous">

<div class="custom-control custom-switch">
  <input type="checkbox" class="custom-control-input" id="customSwitch1">
  <label class="custom-control-label" for="customSwitch1">v4 switch element</label>
</div>

<div class="form-check form-switch">
  <input class="form-check-input" type="checkbox" id="flexSwitchCheckChecked" checked>
  <label class="form-check-label" for="flexSwitchCheckChecked">v5 switch element</label>
</div>

于 2021-04-02T09:24:40.297 回答