简体   繁体   English

页面加载后删除ajax加载器映像

[英]Remove ajax loader image after page load

I have a form with required fields and when the submit button is clicked a loader image appears. 我有一个带有必填字段的表单,当单击“提交”按钮时,出现一个加载器图像。 This has the code: 这具有代码:

jQuery(document).ready(function($){
    {
        $.getElementById('form').onsubmit = function () {
            $.getElementById('submit').style.display = 'block';
            $.getElementById('loading2').style.display = 'block';
        };
    }(document));
)};

HTML: HTML:

<input type="submit" class="button alt"  onclick="$(\'#loading\').show();" id="place_order"/>.

The issue I am having is when the the required fields are not field and the submit button is clicked, the loader images appears and when the required field errors are displayed, the loader image still shows. 我遇到的问题是,当必填字段不是字段并且单击了提交按钮时,出现了加载程序图像,并且当显示必填字段错误时,仍然显示加载程序图像。

How do I prevent it from displaying? 如何防止其显示?

I don't like your use of jquery this way, 我不喜欢您这样使用jquery,

what I do myself is to validate the form and post the result myself with jquery that means better control over everything so my code will be like this: 我自己要做的是验证表单并使用jquery自己发布结果,这意味着可以更好地控制所有内容,因此我的代码将如下所示:

 $('#formBtn').click(function(){ $("#loading").fadeIn(); //use some validation here and let code go to other line if validation passed $.post("/signup",$('#form').serialize(),function(){ //other action like redirecting to homepage or showing a message }).fail(function(){ //to show a message that submit was failed }).always(function(){ $("#loading").fadeOut(); }); }) 

使用jQuery post或get提交表单,然后在回调中验证您的响应,然后在验证完成后使用.hide()。

You try to use jQuery BlockUI Plugin Probably easier. 您尝试使用jQuery BlockUI插件可能会更容易。

jQuery BlockUI Plugi jQuery BlockUI插件

When you want to Block you can use 当您想要阻止时,可以使用

$.blockUI();

When you want to UnBlock you can use 当您想解除封锁时,可以使用

$.unblockUI();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM