如何使用Twitter Bootstrap自动关闭警报

编程入门 行业动态 更新时间:2024-10-11 03:17:20
本文介绍了如何使用Twitter Bootstrap自动关闭警报的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我使用twitter的bootstrap CSS框架(这是太棒了)。对于一些消息给用户,我使用警告Javascript JS和CSS显示它们。

I'm using twitter's bootstrap CSS framework (which is fantastic). For some messages to users I am displaying them using the alerts Javascript JS and CSS.

对于感兴趣的用户,可以在这里找到: http:// getbootstrap。 com / javascript /#alerts

For those interested, it can be found here: getbootstrap/javascript/#alerts

我的问题是这样的;在我向用户显示提醒后,我希望它在一段时间间隔后离开。基于twitter的文档和我看过的代码看起来这不是在:

My issue is this; after I've displayed an alert to a user I'd like it to just go away after some time interval. Based on twitter's docs and the code I've looked through it looks like this is not baked in:

  • 我的第一个问题是请求确认这确实没有进入Bootstrap
  • 其次,如何实现这种行为?
推荐答案

调用window.setTimeout (function,delay) 将允许您完成此操作。下面是一个在显示警报后2秒(或2000毫秒)自动关闭警报的示例。

Calling window.setTimeout(function, delay) will allow you to accomplish this. Here's an example that will automatically close the alert 2 seconds (or 2000 milliseconds) after it is displayed.

$(".alert-message").alert(); window.setTimeout(function() { $(".alert-message").alert('close'); }, 2000);

如果你想把它包装在一个nifty函数中,你可以这样做。

If you want to wrap it in a nifty function you could do this.

function createAutoClosingAlert(selector, delay) { var alert = $(selector).alert(); window.setTimeout(function() { alert.alert('close') }, delay); }

然后你可以这样使用...

Then you could use it like so...

createAutoClosingAlert(".alert-message", 2000);

我确定有更多优雅的方法来完成这个。

I am certain there are more elegant ways to accomplish this.

更多推荐

如何使用Twitter Bootstrap自动关闭警报

本文发布于:2023-11-27 18:56:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1639209.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:警报   如何使用   自动关闭   Bootstrap   Twitter

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!