简体   繁体   English

苹果浏览器iphone ios 7在输入文本焦点上冻结

[英]safari iphone ios 7 Freezes on input text focus

We have a complex application form with a lots of fields and jquery events. 我们有一个复杂的应用程序表单,其中包含许多字段和jquery事件。 The problem is similar to this iOS 7 Safari: OS locks up for 4 seconds when clicking/focusing on a HTML input but in our case, it totally freezes and will never get back to work. 问题类似于此iOS 7 Safari:单击/关注HTML输入时,操作系统锁定4秒钟,但在我们的情况下,它完全死机,永远无法恢复工作。

The problem occurs only in safari in iphone, ANyone have same problem and solution? 该问题仅发生在iPhone的Safari中,ANyone有同样的问题和解决方案吗? thanks 谢谢

Using Binke's solution fixed the delay on the touch events, but then the delay was still present when pressing keys, so capturing the keypress and keydown events worked around this issue for me. 使用Binke的解决方案固定了触摸事件的延迟,但是随后在按下键时仍然存在延迟,因此捕获按键和击键事件对我来说可以解决此问题。 I had to use the keypress event to distinguish between capital and lowercase letters, but the keydown event was required for delete/backspace. 我必须使用keypress事件来区分大写和小写字母,但是对于删除/退格键,keydown事件是必需的。 This basically just captures the key pressed and puts it in the input box (or removes last char for backspace/delete). 基本上,这只是捕获按下的键并将其放在输入框中(或删除用于退格键/删除键的最后一个字符)。 The selectors variable should contain the jquery selector(s) that will include all inputs causing the freezing. 选择器变量应包含将包含导致冻结的所有输入的jquery选择器。 Here is the code we used: 这是我们使用的代码:

    var scroll = 0;    
    var selectors = "#input1, #input2, #input3";
    $(selectors).bind("touchstart", function (e) {
        scroll = document.body.scrollTop;
    });
    //I stripped away some of Binke's code because we were only having an issue with INPUT controls
    $(selectors).bind("touchend", function (e) {
        if (scroll == document.body.scrollTop) { 
            if (e.target.nodeName.toString().toUpperCase() == 'INPUT') {
                e.preventDefault(); 
                e.target.focus();  
                e.target.setSelectionRange(e.target.value.length, e.target.value.length);
            } 
        }
    });
    $(selectors).bind('keydown', function (e) {
        //alert(e.which);
        if (e.which == 8 || e.which == 46) { // BACKSPACE OR DELETE
            $(this).val($(this).val().substring(0, ($(this).val().length - 1)));
            return false;
        }
        else { return true; }
    });
    $(selectors).bind("keypress", function (e) {
        if (e.which != 8 && e.which != 46) {
            $(this).val($(this).val() + String.fromCharCode(e.which));
        }
        return false;
    });

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

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