一段时间后使用Javascript加载网页ASP.net

Loading webpage after some time ASP.net using Javascript

本文关键字:网页 ASP net 加载 Javascript 一段时间      更新时间:2023-09-26

它看起来是重复的,但它花了很多时间,仍然造成了一些问题。请有人指出我做错了什么。

我有一个按钮,当我点击它时,JS函数show()被称为

<input type="button" onclick="show()" value="Add to Cart">

javascript代码位于下方

    function show() {
          document.getElementById("loadingDiv").style.display = "block";
          setTimeout('Redirect()', 2000);
          function Redirect() {
              location.href = 'Index.aspx';
          }

    }

div被正确地设置为,但页面从不重定向。不确定问题出在哪里。

调用redirect函数时,需要删除括号和单引号。

setTimeout(Redirect, 2000);

以下是setTimeout函数的文档。

试试这个。

function show() {
      document.getElementById("loadingDiv").style.display = "block";
      setTimeout(function(){
            location.href = 'Index.aspx';
      }, 2000);
}

或者从CCD_ 3函数体中创建CCD_。

将此行setTimeout('Redirect()', 2000);更改为setTimeout(Redirect(), 2000);

基本上,在setTimeout参数中,函数名不应该在Quotes 中