我想从表中删除一行后重新加载页面,然后显示消息.以下是JavaScript代码:
if(action == 'delete'){
window.location.reload(true);
//tried to set timeout here, no luck :(
document.getElementById('messageSpan').innerHTML = "The value has been deleted.";
}
似乎在更改了messageSpan内容之后执行了重新加载功能,因此重新加载功能清除了messageSpan内容.
解决方法:
如果您尝试在定义的时间段内显示消息,然后重新加载页面,则可以使用setTimeout函数:
if(action == 'delete'){
document.getElementById('messageSpan').innerHTML = "The value has been deleted.";
setTimeout(function () { // wait 3 seconds and reload
window.location.reload(true);
}, 3000);
}
请注意,您的消息仅在这三秒钟内可见,重新加载页面后该消息将消失.