使用jQuery在iPhone iPad浏览器中无法选择焦点上的文本

Sut*_*bey 5 html jquery mobile-website jquery-mobile

我们正在为移动浏览器开发Web-App,我们希望只要输入框获得焦点,就可以选择任何输入框的文本.以下答案修复了Desktop chrome/safari浏览器的问题.以下解决方案适用于Android浏览器,但不适用于iPhone/iPad浏览器,任何解决方案..

$("#souper_fancy").focus(function() { $(this).select() });

$("#souper_fancy").mouseup(function(e){
        e.preventDefault();
});
Run Code Online (Sandbox Code Playgroud)

参考: -

使用jQuery在Safari和Chrome中无法选择焦点上的文本

Sut*_*bey 4

此处找到的答案不知道如何将此问题标记为重复。 在 iOS 设备(移动 Safari)上以编程方式选择输入字段中的文本

我的修复看起来像这样:-

<script type="text/javascript">
           $('div,data-role=page').live('pageshow', function (event) {
               jQuery.validator.unobtrusive.parse(".ui-page-active form");
               $("input[type='text'], textarea, input[type='password'], input[type='number']").live('mouseup', function (e) { e.preventDefault(); });
               $("input[type='text'], textarea, input[type='password'], input[type='number']").live('focus', function () {this.setSelectionRange(0, 9999); });             
           });       
    </script>
Run Code Online (Sandbox Code Playgroud)