以基于时间的方式消失警报框
Disappear the alert box with time based
我想在一定时间后消失警报框。我听说这在Javascript中是不可能的,那么有没有另一种方法可以做到这一点呢?
试试这个 jsbin 代码 - 一个自定义的警报框
http://jsbin.com/ibUrIxu/1/edit
或在您的.html
文件上尝试此操作
法典
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>JS Bin</title>
<script>
function customAlert(msg,duration)
{
var styler = document.createElement("div");
styler.setAttribute("style","border: solid 5px Red;width:auto;height:auto;top:50%;left:40%;background-color:#444;color:Silver");
styler.innerHTML = "<h1>"+msg+"</h1>";
setTimeout(function()
{
styler.parentNode.removeChild(styler);
},duration);
document.body.appendChild(styler);
}
function caller()
{
customAlert("This custom alert box will be closed in 2 seconds","2000");
}
</script>
</head>
<body onload="caller()">
</body>
</html>
工作演示 - 这是一个自定义警报框和您需要的功能
function cancelDiv() {
$("#div1").hide();
}
function ShowDiv() {
$("#div1").css("backgroundColor", "white");
$("#div1").show();
setTimeout(function(){$("#div1").hide()}, 3000)
}
$(function () {
$("#div1").hide();
$("#div1").draggable();
});
您可以使用自定义警报消息来执行此操作。通知框架的一个示例是 ToastR。您还可以创建自己的消息框架。但是,您不能关闭常规的JavaScript警报框。
相关文章:
- 为什么这在IE中的工作方式与在Firefox中不同
- 在AngularJS应用程序中使用封装指令和路由的推荐方式是什么
- Windows8应用程序(html&Javascript):从图片库(除了文件选择器)显示图像的另一种方式
- facebook”;添加评论“;popup获胜'不要消失
- 在localhost Dev Box上测试JSONP请求的最佳方式
- 使用javascript存储变量的最安全方式
- 为什么js事件消失了
- 以可优化的方式使用requirejs加载模板
- 在Highcharts中,我们可以通过任何方式在渲染图表之前获得plotWidth和plotHeight
- 任何方式使AJAX调用Gmail API,而无需通过JS库
- JS文件的路径正在消失
- 为react组件传递道具的最佳方式
- I'我设计了一个下拉菜单,onclick会出现,而on blur会消失
- 让Webpack管理Quirky AMD定义的最佳方式
- 在承诺链中处理早期回报的最佳方式
- 如何“;过滤器”;或者以其他方式重构该数据
- Morris.js折线图x轴标签在调整大小后消失
- 您有更好的动态方式来缩短复杂的代码jquery吗
- 以基于时间的方式消失警报框
- Fabric.js对象在通过编程方式改变属性后消失