纯JavaScript中的进度图像加载器仅当用户单击提交html表单时

问题描述 投票:0回答:1

我想只在用户点击我的html表单上的progress image loader时显示submit但是当用户progress image loader页面时显示reloads ...所以我想隔离事件只有一个点击按钮当用户(submit)页面时没有显示progress image loaderreloads。我提供了一个示例,以显示我在纯JavaScript中寻找的内容。

任何帮助表示赞赏。

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>
  <meta http-equiv="content-type" content="text/html;charset=utf-8">
  <meta name="pragma" content="no-cache">
  <meta name="robots" content="noindex, nofollow">
  <title>BackUp</title>
  <link rel="stylesheet" type="text/css" href="backup.css">
  <script language="javascript" type="text/javascript">
  function StartProgress() {
    ProgressImage = document.getElementById('progress_image');
    document.getElementById("progress").style.display = "block";
    setTimeout("ProgressImage.src = ProgressImage.src", 100);
    return true;
  }
  </script>
</head>

<body onUnload="StartProgress()">

<div class="mainbox">
  <div class="box1">
    <span class="title">BackUp</span>
  </div>
  <div class="cleardiv"></div>
  <div class="box2">
    <form onSubmit="return StartProgress()" action="backup.php" method="post">
    <input class="backup_button" type="submit" name="submit" value="BackUp">
    </form>
  </div>
  <div class="cleardiv"></div>
  <div style="display: none" id="progress"><img id="progress_image" src="css/busy.gif" alt="BackUp in progress..."></div>
  <div class="cleardiv"></div>
</div>

</body>

</html>
javascript html image loader
1个回答
1
投票

你可以试试这个:

将表单更改为以下内容:

<form id='form1' action="backup.php" method="post">
    <input type='button' onclick='submitForm()' value="BackUp" />
</form>

submitForm函数:

function submitForm() {
    StartProgress();
    var form1 = document.getElementById('form1');
    form1.submit();
    //setTimeout(function(){
    //  form1.submit();
    //}, 1000);
}
© www.soinside.com 2019 - 2024. All rights reserved.