我买了一个基于 bootstrap/html 的管理面板,它有很多很棒的功能,其中之一是翻转开关,它看起来非常时尚,我希望将它用于我的任何产品状态。
这就是实际代码的样子
<div data-off-label="Disabled" data-on-label="Enabled" class="switch" style="margin-top:12px;">
<input type="checkbox" checked="checked">
</div>
当我从浏览器中检查元素时,我得到以下信息:
<div data-off-label="Disabled" data-on-label="Enabled" class="switch" style="margin-top:12px;">
<div class="switch-on switch-animate" style="">
<input type="checkbox" checked="checked">
<span class="switch-left">Enabled</span><label>
</label><span class="switch-right">Disabled</span>
</div>
我使用了通常的 data-role="flipswitch" 但这看起来不一样
开机看起来像这样
<div class="switch-on switch-animate">
关机看起来像这样
<div class="switch-off switch animate">
请帮助我如何使用上面的内容根据来自数据库的值加载页面时进行更改。
我试过follow但没用
<div data-off-label="Disabled" data-on-label="Enabled" class="switch" style="margin-top:12px;">
<div class="<?if($Status = 1){ echo 'switch-on'; } else { echo 'switch-off'; } switch-animate" style="">
<input type="checkbox" checked="checked">
<span class="switch-left">Enabled</span><label>
</label><span class="switch-right">Disabled</span>
</div>
开关不能正常工作并停止滑动。
似乎管理面板的开发人员将此模块用于开关
您提供的文档显示复选框状态可以设置为父 div 上的数据属性。
<div data-state="<?php echo ($status == 1) ? 'true' : 'false' ?>" data-off-label="Disabled" data-on-label="Enabled" class="switch" style="margin-top:12px;">
<input type="checkbox" checked="checked">
</div>