如何在窗口位置之前显示消息 2 秒
how to display msg for 2 seconds before window.location
JS:
$.ajax({
url: url,
method: 'POST',
data: data,
}).done(id => {
this._handleMsg('data saved.');
const newUrl = dutils.urls.resolve( 'test', { test_id: id } );
window.location.replace(newUrl);
}).fail(( jqXHR, textStatus, errormsg ) => {
this._handleError('Sorry. Report not saved. Reason:' + errormsg); // eslint-disable-line no-alert
});
_handleMsg(msg) {
if (msg) {
$('#header .form-group').addClass('has-msg');
$('.report-error').html(msg).delay(200000).fadeIn(500000);
} else {
$('#header .form-group').removeClass('has-msg');
}
},
SCSS:
.report-error{
visibility: hidden;
text-align: center;
color: red;
}
.has-msg, .has-msg:focus, .has-msg:hover{
input {
border-color: #843534;
-webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,.075),0 0 6px #ce8483;
box-shadow: inset 0 1px 1px rgba(0,0,0,.075),0 0 6px #ce8483;
background-color: #ffffff;
outline: 0;
}
label, .report-error{
visibility: visible;
color: green;
font-size:30px;
}
}
我需要显示消息"数据已保存"2秒钟,然后重定向到另一个URL。 但似乎 $('.report-error').html(msg).delay(200000).fadeIn(500000); 不起作用。
知道吗?谢谢
更新
203 this._handleMsg('data saved.');
204 setTimeout(()=>{
205 const newUrl = dutils.urls.resolve( 'test', { test_id: id } );
206 window.location.replace(newUrl);
207 }, 2000);
$.ajax({
url: url,
method: 'POST',
data: data,
}).done(id => {
this._handleMsg('data saved.');
const newUrl = dutils.urls.resolve( 'test', { test_id: id } );
//below function will call after 2s that solve your purpose
setTimeout(function () { window.location.replace(newUrl); }, 2000);
}).fail(( jqXHR, textStatus, errormsg ) => {
this._handleError('Sorry. Report not saved. Reason:' + errormsg); // eslint-disable-line no-alert
});
试试 JavaScript 的超时:setTimeout()
(查看此处了解更多信息)
这是一个使用 setTimeout 和调用带有参数的函数的小提琴。
代码本身如下所示:
function alertMessage(firstMessage, secondMessage) {
alert(firstMessage + ' ' + secondMessage);
}
setTimeout(
alertMessage, // name of the function to be called after the delay
1000, // the size of the delay in ms
'Hello world!', // the first parameter to be parsed to the called function
'You rock!' // the second parameter to be parsed to the called function
);
我希望这有所帮助。
相关文章:
- 如果下载不成功,如何显示消息
- 如何在 jquery 中的速率按钮下方显示消息状态
- 删除所有可拖动元素后如何显示消息
- php表单验证n在表单上显示消息3秒钟并淡出
- 单击“点赞”按钮时显示消息
- javascript初学者-无法在屏幕上显示消息框
- 在表单提交后显示消息的方法
- 遍历列表,并在jQuery为空时显示消息
- 在jquery幻灯片登录表单上显示消息
- 如果文本筛选器在ng重复中未返回结果,则显示消息
- 以javascript显示消息框
- 在angular 1中,我如何检测angular是否受支持,并在屏幕上显示消息's不受支持
- 浏览器全屏显示,按键时不显示消息
- 选取随机数组元素,将其移除,并在没有更多可用元素时显示消息
- 仅当浏览器不是Google Chrome时显示消息
- 如果所有李都被隐藏,则显示消息
- 在提交表单和显示消息之前,如何检查表单输入是否全是数字
- 如果使用 JavaScript 登录失败,如何在登录页面中显示消息
- j查询验证未显示消息
- 为什么不显示消息