消息淡出后重新加载页面
Reload page after message faded out
我想在显示消息后重新加载页面。
这是我的代码。
ASPX:
<div id="MyMsg" style="display:none;color:red; text-align: center;" runat="server">
<h2>This card has expired</h2>
<h2>Please see front desk</h2>
</div>
Javascript:
<script>
setTimeout(function () {
$('#MyMsg').fadeOut('fast');
}, 5000) // <-- time in milliseconds
window.location.reload();
</script>
C#:
{
MyMsg.Style.Add("display", "normal");
btnSubmit.Enabled = false;
IDCard.Text = "";
IDCard.Visible = true;
IDCard.Focus();
}
希望有人能给我指出正确的方向。
如何在此脚本中重新加载页面
setTimeout(function () {
$('#MyMsg').fadeOut('fast');
}, 5000); // <-- time in milliseconds
是不是应该这样
当我尝试此操作时,页面根本无法启动
<script>
//setTimeout(function () {
// $('#MyMsg').fadeOut('fast');
//}, 5000); // <-- time in milliseconds
const fadePromise = new Promise((resolve, reject) => {
$('#MyMsg').fadeOut('fast');
resolve();
});
// Now invoke the fadePromise and use then-block
fadePromise.then(() => {
window.location.reload();
});
只需将 window 重新加载放在 setTimeout() 中,如下所示:
<script>
setTimeout(window.location.reload, 5000);
</script>
除非褪色是强制性的,在这种情况下,您可以晚一点调用重新加载函数,如下所示:
<script>
// fade after 5 seconds
setTimeout(() => {
$('#MyMsg').fadeOut('fast');
}, 5000);
// on 6th second, reload the page
setTimeout(window.location.reload, 6000);
</script>
P.S:我知道它已经一个月大了,但我真诚地希望这对你有帮助,如果你还没有自己找到的话:)
我想在显示消息后重新加载页面。 这是我的代码。
ASPX:
<div id="MyMsg" style="display:none;color:red; text-align: center;" runat="server">
<h2>This card has expired</h2>
<h2>Please see front desk</h2>
</div>
Javascript:
<script>
setTimeout(function () {
$('#MyMsg').fadeOut('fast');
}, 5000) // <-- time in milliseconds
window.location.reload();
</script>
C#:
{
MyMsg.Style.Add("display", "normal");
btnSubmit.Enabled = false;
IDCard.Text = "";
IDCard.Visible = true;
IDCard.Focus();
}
希望有人能给我指出正确的方向。
如何在此脚本中重新加载页面
setTimeout(function () {
$('#MyMsg').fadeOut('fast');
}, 5000); // <-- time in milliseconds
是不是应该这样 当我尝试此操作时,页面根本无法启动
<script>
//setTimeout(function () {
// $('#MyMsg').fadeOut('fast');
//}, 5000); // <-- time in milliseconds
const fadePromise = new Promise((resolve, reject) => {
$('#MyMsg').fadeOut('fast');
resolve();
});
// Now invoke the fadePromise and use then-block
fadePromise.then(() => {
window.location.reload();
});
只需将 window 重新加载放在 setTimeout() 中,如下所示:
<script>
setTimeout(window.location.reload, 5000);
</script>
除非褪色是强制性的,在这种情况下,您可以晚一点调用重新加载函数,如下所示:
<script>
// fade after 5 seconds
setTimeout(() => {
$('#MyMsg').fadeOut('fast');
}, 5000);
// on 6th second, reload the page
setTimeout(window.location.reload, 6000);
</script>
P.S:我知道它已经一个月大了,但我真诚地希望这对你有帮助,如果你还没有自己找到的话:)