Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/285.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript “如何加载进度条”;点击";使用php_Javascript_Php - Fatal编程技术网

Javascript “如何加载进度条”;点击";使用php

Javascript “如何加载进度条”;点击";使用php,javascript,php,Javascript,Php,我想在php脚本运行时显示进度,这样用户就不会在welcome.php中单击send按钮两次,但这不会在单击时显示处理,而是在操作完成后显示处理,而我的意图是在操作执行时单击一次 <html> <head> <script> function myFunction() { document.getElementById("display").innerHTML = "Processing . . ."; } &

我想在php脚本运行时显示进度,这样用户就不会在welcome.php中单击send按钮两次,但这不会在单击时显示处理,而是在操作完成后显示处理,而我的意图是在操作执行时单击一次

<html>

<head>
    <script>
    function myFunction() {
        document.getElementById("display").innerHTML = "Processing . . .";
    }
    </script>
</head>

<body>
    <form action="ratings.php" method="post">
        Insert URL :
        <input type="text" name="id">
        <br> Number Of Reviews:
        <input type="number" name="number">
        <br>
        <input type="submit" onclick="myFunction()">
    </form>
    <p id="display"></p>
</body>

</html>

函数myFunction(){
document.getElementById(“显示”).innerHTML=“处理…”;
}
插入URL:

审查次数:


试试这个版本的js:

<script type="text/javascript">
function ButtonClicked()
{
   document.getElementById("formsubmitbutton").style.display = "none"; // to undisplay
   document.getElementById("buttonreplacement").style.display = ""; // to display
   return true;
}
var FirstLoading = true;
function RestoreSubmitButton()
{
   if( FirstLoading )
   {
      FirstLoading = false;
      return;
   }
   document.getElementById("formsubmitbutton").style.display = ""; // to display
   document.getElementById("buttonreplacement").style.display = "none"; // to undisplay
}
document.onfocus = RestoreSubmitButton;
</script>

函数按钮单击()
{
document.getElementById(“formsubmitbutton”).style.display=“none”//取消显示
document.getElementById(“按钮替换”).style.display=“”;//显示
返回true;
}
var FirstLoading=真;
函数RestoreSubmitButton()
{
if(首次加载)
{
firstload=false;
返回;
}
document.getElementById(“formsubmitbutton”).style.display=“”;//显示
document.getElementById(“buttonreplacement”).style.display=“none”//取消显示
}
document.onfocus=恢复SubmitButton;
创建两个按钮并隐藏一个

<input id="buttonreplacement" style="display:none;" type="submit"  Value="Processing . . .">
<input  id="formsubmitbutton" type="submit" Value="Submit">

Jquery版本。不要使用submit按钮,而是使用id为的span或div。单击span时,触发代码并提交表单

<html>
    <head>
        <script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
    </head>

    <body>
        <form action="ratings.php" method="post" id="ratings">
            Insert URL :
            <input type="text" name="id">
            <br> Number Of Reviews:
            <input type="number" name="number">
            <br>
            <!-- Add css to make the span look like button -->
            <span id="submit_form">Submit</span>
        </form>
        <span id="display"></span>
        <script>
        $(document).ready(function(){
            // Initialize submitted with false
            var submitted = false;
            // Onclick Submit span.
            $("#submit_form").click(function(){
                $("#display").html("Processing....");
                // Form is submitted.
                if(!submitted)
                {
                    // Submitting the form using its id.
                    $("#ratings").submit();
                }
                // On first click submitted will be change to true.
                // On the next click the submitted variable will be as true.
                // So the above if condition will not be executed after the first time.
                if(!submitted)
                    submitted= true;
            });
        });
        </script>
    </body>
    </html>

插入URL:

审查次数:
提交 $(文档).ready(函数(){ //初始化提交时使用false var=false; //单击提交范围。 $(“#提交表格”)。单击(函数(){ $(“#显示”).html(“处理…”); //表格已提交。 如果(!已提交) { //使用表单id提交表单。 $(“#评级”).submit(); } //第一次单击“提交”时,将更改为“真”。 //下一次单击时,提交的变量将为true。 //因此,在第一次之后将不会执行上述if条件。 如果(!已提交) 提交=真实; }); });
更新

演示:

希望对你有帮助

更新

根据@ibad gore的建议,您可以使用ajax处理php文件,而无需重新加载页面

<html>
<head>
    <script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
</head>

<body>
    <form action="ratings.php" method="post" id="ratings">
        Insert URL :
        <input type="text" name="id">
        <br> Number Of Reviews:
        <input type="number" name="number">
        <br>
        <!-- Add css to make the span look like button -->
        <span id="submit_form">Submit</span>
    </form>
    <span id="display"></span>
    <script>
    $(document).ready(function(){
        // Initialize submitted with false
        var submitted = false;
        var form=$("#ratings");
        $("#submit_form").click(function(){
            $("#display").html("Processing....");
            // Form is submitted.
            if(!submitted)
            {
                // Submitting the form using ajax.
                $.ajax({
                    type:"POST",
                    url:form.attr("action"),
                    data:$("#ratings input").serialize(),//only input
                    success: function(response, status){
                        if(status=="success")
                        {
                            submitted = false;
                            $("#display").html("Submitted");
                        }
                    }
                });
            }
            // On first click submitted will be change to true.
            // On the next click the submitted variable will be as true.
            // So the above if condition will not be executed after the first time.
            if(!submitted)
                submitted= true;
        });
    });
    </script>
</body>
</html>

插入URL:

审查次数:
提交 $(文档).ready(函数(){ //初始化提交时使用false var=false; 风险值形式=$(“#评级”); $(“#提交表格”)。单击(函数(){ $(“#显示”).html(“处理…”); //表格已提交。 如果(!已提交) { //使用ajax提交表单。 $.ajax({ 类型:“POST”, url:form.attr(“操作”), 数据:$(“#评级输入”).serialize(),//仅输入 成功:功能(响应、状态){ 如果(状态=“成功”) { 提交=错误; $(“#显示”).html(“已提交”); } } }); } //第一次单击“提交”时,将更改为“真”。 //下一次单击时,提交的变量将为true。 //因此,在第一次之后将不会执行上述if条件。 如果(!已提交) 提交=真实; }); });
要实现这一点,只需单击,显示进度条,然后通过AJAX提交表单。

表单的PHP处理完成后,您可以使用
window.location


在这种情况下,我想这是最好的做法。

试试我的答案,我测试过了,效果很好,让我知道它是否符合您的要求

@导入url(http://fonts.googleapis.com/css?family=Roboto+浓缩);
.盒子{
填充:20px;
保证金:0自动;
显示:内联块;
垂直对齐:中间对齐;
文本对齐:居中;
边框:#C0 3px实心;
边界半径:5px;
最小宽度:270px;
高度:240px;
字体系列:“Roboto Compressed”、“Helvetica Neue”、Helvetica、Arial、无衬线字体;
字体大小:15px;
字体风格:普通;
线高:正常;
字体大小:正常;
字体变体:正常;
背景色#006699;
}
.评级{
填充:10px;
保证金:0自动;
字体系列:“Roboto Compressed”、“Helvetica Neue”、Helvetica、Arial、无衬线字体;
字号:17px;
字体风格:普通;
线高:正常;
字体大小:正常;
字体变体:正常;
背景色:暗色;
颜色:黑色;
边界半径:5px;
边框:#C0 3px实心;
长方体阴影:插图-5px 5px rgba(255,255,255,0.15),插图-5px 5px rgba(0,0,0,0.15);
光标:指针;
}
输入{
背景色:#C0;
边框:2倍纯色灰色;
边界半径:3px;
}
#进展{
填充:20px;
}
克利尔迪夫先生{
明确:两者皆有;
}

评级
函数SubmitForm(){
StartProgress();
var评级=document.getElementById(“评级”);
评级。提交();
}
函数StartProgress(){
ProgressImage=document.getElementById('progress_image');
document.getElementById(“progress”).style.display=“block”;
setTimeout(“ProgressImage.src=ProgressImage.src”,100);
返回true;
}
插入URL:



审查次数: