【问题标题】:How to redirect to another page after form submition using a loading screen如何在使用加载屏幕提交表单后重定向到另一个页面
【发布时间】:2021-12-30 07:35:24
【问题描述】:
<form action='page.html' 
method='post'>
<input type="text" name="name" placeholder="Enter your name here"> 
<input type="submit" value="submit">
</form>

在上面的代码中,表单提交后会有大约 5 秒的加载屏幕或图标(图标更好),然后它会重定向到 page.html。我是 Web Dev 世界的新手,所以请帮助我任何有编码部分的人。我不知道如何使用 javascript 或 jQuery。

【问题讨论】:

    标签: javascript html jquery


    【解决方案1】:

    您可以使用字体真棒微调图标,此代码将在输入字段下方显示微调图标 5 秒。您可以根据需要更改其位置。

    <html>
    <head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
    </head>
    <body>
    
    <form action='page.html' method='post' onSubmit="return showSpinner(this);">
    <input type="text" name="name" placeholder="Enter your name here"> 
    <input type="submit" value="submit">
    </form>
    <i class="fa fa-spinner fa-pulse" style="font-size:24px;visibility:hidden" id="spinner-icon"></i>
    
    <script>
        const showSpinner = form => {
            // Display the spinner icon
            document.getElementById("spinner-icon").style.visibility = "visible";
            // Wait 5 seconds then submit form
            setTimeout(function() {
                form.submit();
            }, 5000);  // 5 seconds
            
            return false;
        }
    </script>
    </body>
    </html>
    

    【讨论】:

      【解决方案2】:
      <form action='page.html' method='post' onsubmit="myFunction()">
      <input type="text" name="name" placeholder="Enter your name here"> 
      <input type="submit" value="submit">
      </form>
      
      <script>
      function myFunction() {
        alert("The form was submitted");
      }
      </script>
      

      【讨论】:

        猜你喜欢
        • 2017-06-26
        • 1970-01-01
        • 1970-01-01
        • 2013-06-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-07-18
        相关资源
        最近更新 更多