繁体   English   中英

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

[英]Remove ajax loader image after page load

我有一个带有必填字段的表单,当单击“提交”按钮时,出现一个加载器图像。 这具有代码:

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

HTML:

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

我遇到的问题是,当必填字段不是字段并且单击了提交按钮时,出现了加载程序图像,并且当显示必填字段错误时,仍然显示加载程序图像。

如何防止其显示?

我不喜欢您这样使用jquery,

我自己要做的是验证表单并使用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()。

您尝试使用jQuery BlockUI插件可能会更容易。

jQuery BlockUI插件

当您想要阻止时,可以使用

$.blockUI();

当您想解除封锁时,可以使用

$.unblockUI();

暂无
暂无

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

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