[英]Bootstrap 4 Toggle Checkbox within Dropdown menu
I placed a checkbox styled with Bootstrap Toggle Plugin ( http://www.bootstraptoggle.com/ ) in a Bootstrap 4 dropdown menu ( https://getbootstrap.com/docs/4.0/components/dropdowns/ ).我在 Bootstrap 4 下拉菜单 ( https://getbootstrap.com/docs/4.0/components/dropdowns/ ) 中放置了一个带有 Bootstrap Toggle Plugin ( http://www.bootstraptoggle.com/ ) 样式的复选框。 When I click the toggle, the menu gets closed immediately.
当我单击切换按钮时,菜单会立即关闭。
I can prevent this by using onclick="event.stopPropagation();"
我可以通过使用
onclick="event.stopPropagation();"
来防止这种情况发生on the menu item (code from here: Keep Bootstrap dropdown open on click ).在菜单项上(来自此处的代码: 单击时保持 Bootstrap 下拉菜单打开)。 But then, the toggle switch does not work anymore.
但是,拨动开关不再起作用。
Is there a way to have the menu stay open when the toggle is clicked?有没有办法在单击切换时让菜单保持打开状态?
if you wrap your toggle inside a form-tag it should not close the dropdown.如果您将切换开关包裹在表单标签中,则不应关闭下拉列表。
http://jsfiddle.net/mjhr0f6d/2/ http://jsfiddle.net/mjhr0f6d/2/
...
<form>
<input type="checkbox" checked data-toggle="toggle">wrapped inside form
</form>
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.