如何通过单击按钮来打开和关闭引导警报? [英] How to toggle a bootstrap alert on and off with button click?

查看:101
本文介绍了如何通过单击按钮来打开和关闭引导警报?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过按钮单击事件多次显示警报框,而不必刷新页面,但是警报框仅显示一次.如果要再次显示警报框,则必须刷新页面.

I want to display an alert box multiple times with a button click event without having to refresh the page but the alert box only shows up once. If I want to show the alert box again, I have to refresh page.

当前,如果在页面上呈现引导警报,则在关闭引导警报时,警报的div容器将从页面中消失.因此,当您再次单击该按钮时,它不再显示.我一直在关闭按钮上执行以下操作,以使其隐藏而不是删除警报的div容器.

Currently if you render a bootstrap alert on the page, when you close it, the div container of the alert is gone from the page. So when you click the button again, it doesn't show up anymore. I have been doing the following on the close button to make it hide instead of delete the div container of alert.

<button class="close" onclick="$('#alertBox').hide();; return false;">×</button>

我想知道在引导程序中使用data-toggle或data-dismiss是否可以使这种切换效果工作而无需通过我自己的自定义Javascript处理程序.

I wonder if using data-toggle or data-dismiss in bootstrap can make this sort of toggle effect working without going through my own custom Javascript handlers.

推荐答案

我遇到了同样的问题:只是不要使用关闭按钮中的data-dismiss并使用JQuery show()hide():

I've had the same problem: just don't use the data-dismiss from the close button and work with JQuery show() and hide():

$('.close').click(function() {
   $('.alert').hide();
})

现在,您可以使用以下代码在单击按钮时显示警报:

Now you can show the alert when clicking a button by using the code:

$('.alert').show()

希望这会有所帮助!

这篇关于如何通过单击按钮来打开和关闭引导警报?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆