如果submit handler返回true,则在Safari中不执行jQuery show()函数 [英] jQuery show() function is not executed in Safari if submit handler returns true

查看:113
本文介绍了如果submit handler返回true,则在Safari中不执行jQuery show()函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,我已经将一个提交事件处理程序绑定到表单。处理程序设置为验证数据,然后在验证通过后禁用进一步的表单提交,以及显示请稍候...处理消息。

Ok, I've bound a submit event handler to a form. The handler is set up to validate data, then after validation passes disable further form submittal, as well as display a 'Please wait ... processing' message.

这是基本结构:

function handler() {
    // Validation stuff goes here.
    ...
    // Validation passes, show message and return true.
    $('#processing-msg').show();  // Show the 'processing' message.
    $form.bind('submit', function() { return false }); // Disable further form submits.
    return true;  // Proceed with form submittal.
}

直到最后返回语句,如果我在返回true 之前中断,则会显示处理消息。但是,如果我允许它返回true ,那么消息根本不会显示出来。此外,提交按钮也不会显示为禁用(过程的另一部分)。除了Safari之外,这几乎适用于所有浏览器。我已经尝试评论提交禁用逻辑,但没有骰子。

Up until the very last return statement, if I break before return true, the processing message will show. But if I allow it to return true the message doesn't show up at all, ever. Also the submit button won't appear disabled (another part of the process). This works in pretty much every browser except Safari. I've tried commenting out the submit-disable logic, but no dice.

我没有'能够在jsfiddle上完全重新创建问题。但是在这里你可以看到所谓的函数顺序在Safari中是如何不同的( alerts()在显示消息之前发生): http://jsfiddle.net/skttw/3/

I haven't been able to completely re-create the issue on jsfiddle. But here you can see how the order of functions called differs in Safari (alerts() happen before message is displayed): http://jsfiddle.net/skttw/3/

推荐答案

提出这个问题后得出了答案:未执行的JavaScript命令在Safari中订购

Asking this question led to the answer: JavaScript commands not executed in order in Safari

显然,Safari根据内部抽搐呈现对HTML的更改。因此,所有称为的函数都是按顺序执行,但不一定呈现

Apparently Safari renders changes to the HTML according to its internal tics. So all of the functions called are being executed in order, but are not necessarily rendered yet.

此外,在执行某些功能期间暂停渲染, alert()成为其中之一,并且我的情况, onsubmit 事件!这就是为什么我看到无序的结果。

Also, rendering is halted during the execution of certain functions, alert() being one of them, and in my case, the onsubmit event! That was why I was seeing the out-of-order looking results.

所以我最终使用了一点肮脏:

So I ended up using a bit of dirtiness:

            var show = function() { $('#processing_msg').show() };
            setTimeout(show,0);

这篇关于如果submit handler返回true,则在Safari中不执行jQuery show()函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆