【问题标题】:Loading screen after submitting form提交表单后加载屏幕
【发布时间】:2014-04-10 13:35:42
【问题描述】:

我已经添加了这个脚本。

<script>
    $(document).ready(function() { 
        $('#submit-button').click(function() { 
            $.blockUI({ css: { 
                border: 'none', 
                padding: '15px', 
                backgroundColor: '#000', 
                '-webkit-border-radius': '10px', 
                '-moz-border-radius': '10px', 
                opacity: .5, 
                color: '#fff' 
            } }); 

            setTimeout($.unblockUI, 8000); 
        }); 
    }); 

</script>

这是我的输入类型提交。

<input type="submit" name="submit" value="AM I ELIGIBLE?" id="submit-button" >

现在,问题是,一旦我单击提交按钮,加载屏幕也会运行,即使我没有为其他输入类型(名字、电话号码、电子邮件)设置输入。 :(

我希望它在表单验证正常后运行。

我正在使用 jquery.blockUI.js

谢谢你们! :)

这是我的新代码:

<script>
        $(document).ready(function() { 
            $('#submit-button').click(function() { 


            //First set your var for the fields you want. the $() is the id of the field in your html 
                var firstName = $("#first-name").text();
                var lastName = $("#last-name").text();
                if(firstName != "")//&&(lastName != ""))
                {

                $.blockUI({ css: { 
                    border: 'none', 
                    padding: '15px', 
                    backgroundColor: '#000', 
                    '-webkit-border-radius': '10px', 
                    '-moz-border-radius': '10px', 
                    opacity: .5, 
                    color: '#fff' 
                } }); 

                setTimeout($.unblockUI, 8000); 

                }
                // else{
                // // in here you'll do what ever you wanted to for instance.

                // alert("Please make sure all fields are filled out");
                // }

            });         
        }); 

        </script>

---

现在,我有一个滑块..

<p class="slider1">Your approximate total debt: 
  <output name="slider_output1" id="slider_output1" for="form_slider1">0</output><br>                                                   
  <input type="range" class="form_slider1" name="form_slider1" id="form_slider1"
   value="0" min="0" max="60000" step="100" 
   oninput="slider_output1.value=form_slider1.value" 
   onchange="slider_output1.value=value"/>  

</p>

我需要在条件语句中添加这个,这样如果它的值为“0”,表单就不会通过。

我试过用这个..

var slider1 = $("#form_slider1").val();

那么, if(firstName != "" && lastName != "" && email != "" && phone != "" && doorNumber != "" && postcode != "" && (phoneLength.length > 9 || phoneLength.length 0 )

但是,我认为忽略slider1>0,加载屏幕也没有显示。

如果不清楚,请告诉我。 :(

【问题讨论】:

  • 在click函数中添加if语句,检查输入字段是否有信息!
  • 它确实有效,它现在不显示加载屏幕(当输入字段为空时)。但是即使所有输入不再为空,加载屏幕也没有显示。 :(
  • 将输入类型从type="submit" 更改为type="button" 并在.click() 函数中提交表单
  • 感谢大家的帮助!欣赏它! :)

标签: javascript php jquery html forms


【解决方案1】:

您在正确的道路上,您首先需要做的是检查这些字段。

           <script>
    $(document).ready(function() { 
        $('#submit-button').click(function() {
//First set your var for the fields you want. the $() is the id of the field in your html 
var firstName = $("#FirstName").text();
if(firstName != "")
{
            $.blockUI({ css: { 
                border: 'none', 
                padding: '15px', 
                backgroundColor: '#000', 
                '-webkit-border-radius': '10px', 
                '-moz-border-radius': '10px', 
                opacity: .5, 
                color: '#fff' 
            } }); 
 setTimeout($.unblockUI, 8000);
}else{
// in here you'll do what ever you wanted to for instance.

alert("Please make sure all fields are filled out");
}

        }); 
    }); 

</script>

试试这个

<script>
    $(document).ready(function() { 
        $('#submit-button').click(function() { 


        //First set your var for the fields you want. the $() is the id of the field in your html 
            var firstName = $("#first-name").text().trim();
            var lastName = $("#last-name").text().trim();
           //Also use alert to make sure the field are really being filled out
            alert(firstName + " " + lastName);

            if(firstName == "" && lastName == "")
            {
             // // in here you'll do what ever you wanted to for instance.
              alert("Please make sure all fields are filled out");
            }
            else{

              $.blockUI({ css: { 
                border: 'none', 
                padding: '15px', 
                backgroundColor: '#000', 
                '-webkit-border-radius': '10px', 
                '-moz-border-radius': '10px', 
                opacity: .5, 
                color: '#fff' 
            } }); 

            setTimeout($.unblockUI, 8000); 

           }

        });         
    }); 

    </script>

【讨论】:

  • 它确实有效,它现在不显示加载屏幕(当输入字段为空时)。但是即使所有输入不再为空,加载屏幕也没有显示。 :(
  • 即使字段为空,您是否希望它显示加载?您也可以粘贴您的新代码以便我查看吗?
  • 我刚刚将新代码添加到我的第一篇文章中。我的意思是,即使所有字段都有值,点击提交按钮后加载屏幕也不会显示。
  • 我在旧帖子中添加了您上面所说的内容,试试看
  • 请给我看你的 html,看起来你的名字和姓氏没有被正确使用。实际上再尝试一件事,我相信这会有所帮助。更改这些 $("#first-name").text().trim(); $("#last-name").text().trim();这些 $("#first-name").val().trim(); $("#last-name").val().trim();
【解决方案2】:

这应该可行,我将 .text() 更改为 .val()。我还在您的网站上注意到,当您按下 f12 时,您需要处理两个错误。

<script>
$(document).ready(function() { 
    $('#submit-button').click(function() { 


    //First set your var for the fields you want. the $() is the id of the field in your html 
        var firstName = $("#first-name").val().trim();
        var lastName = $("#last-name").val().trim();
       //Also use alert to make sure the field are really being filled out
        alert(firstName + " " + lastName);

        if(firstName == "" && lastName == "")
        {
         // // in here you'll do what ever you wanted to for instance.
          alert("Please make sure all fields are filled out");
        }
        else{

          $.blockUI({ css: { 
            border: 'none', 
            padding: '15px', 
            backgroundColor: '#000', 
            '-webkit-border-radius': '10px', 
            '-moz-border-radius': '10px', 
            opacity: .5, 
            color: '#fff' 
        } }); 

        setTimeout($.unblockUI, 8000); 

       }

    });         
}); 

</script>

【讨论】:

  • 没问题很高兴我能帮忙
  • 还有一件事。 :( 我在第一篇文章中添加了新问题。
  • 你做了警报吗(slider1);看看它是否带回了一个价值?
  • 使用它来恢复滑块的实际值 $("#form_slider1").rangeinput();另外,我建议不要为类和 id 使用相同的名称。
猜你喜欢
  • 1970-01-01
  • 2016-03-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-08-01
  • 2017-09-24
  • 1970-01-01
相关资源
最近更新 更多