3

我想从表中删除一行后重新加载页面,然后显示消息。下面是 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内容。

4

4 回答 4

1

如果您尝试在定义的时间段内显示消息,然后重新加载页面,则可以使用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);
}

请注意,您的消息仅在这三秒钟内可见,当页面重新加载时它将消失。

于 2009-10-08T23:49:40.427 回答
1

不要使用重新加载。使用查询字符串将值传递回您的页面,以告诉它删除操作是否成功

即 self.location.href = "yourPage.html?result=success"

然后,您的页面应检查结果查询字符串项并显示适当的消息。

但是看看 jquery 和 ajax,你可能根本不需要回发来刷新你的网格

于 2010-03-30T14:04:42.297 回答
1

刷新页面后显示消息可以通过以下方式完成:

HTML(在 BODY 标签的任何地方插入):

<div id="dvLoading"></div>

CSS

#dvLoading {
    background:url(../theImages/loader.gif) no-repeat center center;
    height: 100px;
    width: 100px;
    position: fixed;
    left: 50%;
    top: 50%;
    margin: -25px 0 0 -25px;
    z-index: 9999999999999999;
}

查询

$(window).load(function() {
    $('#dvLoading').fadeOut(2000);
});

装载机图片:

装载机

对我来说就像一个魅力。希望对您的问题有所帮助。

于 2013-05-22T21:08:40.293 回答
0

重新加载页面将破坏页面的状态,因此用户将永远不会看到消息 HTML,因为它被页面重新加载重置。

于 2009-10-08T23:51:05.707 回答