【发布时间】:2019-10-17 15:56:24
【问题描述】:
我正在尝试动态显示引导警报 https://getbootstrap.com/docs/4.3/components/alerts/ 一旦用户单击“确定”按钮,就会显示一条使用 cookie 接受的消息,警报消息应该消失,并且在该会话期间不会再次显示给该用户。
不幸的是,我在引导站点上找不到允许以编程方式打开引导警报的文档。因此,每次刷新网站时,都会再次弹出警报。
<div class="alert fade show cookie-alert" role="alert" data-dismiss="alert">
<div class="container">
This website stores cookies. These cookies are used to collect information about how you interact with our website, we use this information to improve and customize your browsing experience. Read our <a target="_blank" href="http://assets.investnow.ng/InvestNow_TC.pdf" style="color:gray;font-weight:bold">terms and conditions</a> to learn more.
<button type="button" class="btn btn-danger btn-sm pull-right cookie-btn okbtn" data-dismiss="alert" aria-label="Close">OK</button>
</div>
</div>
【问题讨论】:
-
它不会打开警报,我已经尝试过了。
-
我已将我正在使用的 HTML sn-p 添加到问题中。
-
正如你所说,这是一个“引导警报”,而不是“模式”(当你说“打开警报”时有点混乱,因为你没有“打开”警报,您“打开”一个对话框)。您可以简单地不显示警报,然后仅在需要时显示它。
<div class='alertstyle='display:none;'`if (showalert) $(".alert").slideDown().您还可以将内联 javascript 与 document.write 一起使用,以便仅在需要时输出警报,但大多数人会建议不要这样做。
标签: javascript jquery html session-storage alerts