douka19950505 2016-07-22 08:42
浏览 66
已采纳

POST时显示div元素的php

I need to show the progress bar when I click the button submit. Below is the code, when I click the button the console is printing the message but, the div element converting_prog is not showing.

What wrong with below code?

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
        <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.0/jquery.js" type="text/javascript"></script>
        <?php
            //process the forms and upload the files
            if ($_POST) {
                //specify folder for file upload
                $user = $_GET["user"];
                ?>
                <script>
                    console.log("posting...");
                </script>
                <script type="text/javascript">document.getElementById('converting_prog').style.display = 'block';</script>
                <?php
            }
        ?>
    </head>
    <body>
        <div id="outPopUp">
            <form action="" method="post" enctype="multipart/form-data" name="form1" id="form1">
                <input class="btn" name="submit" type="submit" id="submit" value="Submit"/>
            </form>
            <div id="converting_prog" class="progress" style="display:none; margin-right:20px;margin-left:20px;margin-top:20px;width:auto">
                <div class="progress-bar progress-bar-striped active" role="progressbar" aria-valuenow="40" aria-valuemin="0" aria-valuemax="100" style="width:100%">
                    Converting %
                </div>
            </div>
        </div>
    </body>
</html>
  • 写回答

4条回答 默认 最新

  • douling0053 2016-07-22 08:45
    关注

    When it runs, the DOM hasn't loaded yet. Try moving the whole PHP if block to the end of the page, so that the JS can run later.

    Or you could wrap that script in a window.onload = function(){} handler.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog