我设置了daisyUI,但没有弄清楚如何按条件控制模态
我认为与flowbite或bootstrap https://flowbite.com/docs/components/modal/类似
但是daisyUI还没有实现隐藏类,并且有
库中的模态开放方法
https://daisyui.com/components/modal/
<link href="https://cdn.jsdelivr.net/npm/daisyui@2.13.6/dist/full.css" rel="stylesheet" type="text/css" />
<script src="https://cdn.tailwindcss.com"></script>
<!-- The button to open modal -->
<label for="my-modal-4" class="btn modal-button">open modal</label>
<!-- Put this part before </body> tag -->
<input type="checkbox" id="my-modal-4" class="modal-toggle">
<label for="my-modal-4" class="modal cursor-pointer">
<label class="modal-box relative" for="">
<h3 class="text-lg font-bold">Congratulations random Interner user!</h3>
<p class="py-4">You've been selected for a chance to get one year of subscription to use Wikipedia for free!</p>
</label>
</label>
那么我们如何配置模态视图呈现visible呢?
非常感谢
3条答案
按热度按时间v9tzhpje1#
另一种方法是操作modal div之前插入的input checkbox元素。如果你控制台记录这个元素的值,你会注意到当模型打开时它被设置为“true”,当模型关闭时它被设置为“false”。
如果您希望默认打开模态,可以用途:
当呈现页面/组件时
f87krz0w2#
只需按照modal-id动态添加/删除属性,JavaScript的.modal-open类就可以完成
hrirmatl3#
我知道这是个老问题了但也许能在将来帮上忙,
如果使用react,则可以将输入的选中属性绑定到状态