使用 jQuery 选择焦点文本在 iPhone iPad 浏览器中不起作用 [英] Selecting text on focus using jQuery not working in iPhone iPad Browsers

查看:19
本文介绍了使用 jQuery 选择焦点文本在 iPhone iPad 浏览器中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在为移动浏览器开发 Web 应用程序,我们希望在输入框获得焦点时选择任何输入框的文本.以下答案解决了桌面 Chrome/safari 浏览器的问题.以下解决方案适用于 Android 浏览器,但不适用于 iPhone/iPad 浏览器,任何解决方案..

We are developing Web-App for Mobile browsers, we would like text of any input box to get selected whenever input-box get focus. Below answer fixes the issue for Desktop chrome/safari browser. Below solution works fine on Android browser, but not on iPhone/iPad browsers, any solution..

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

$("#souper_fancy").mouseup(function(e){
        e.preventDefault();
});

参考:-

选择焦点文本使用jQuery 在 Safari 和 Chrome 中不起作用

推荐答案

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

Answer found here don't know how to mark this question as duplicate. Programmatically selecting text in an input field on iOS devices (mobile Safari)

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

My fix look like this:-

<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>

这篇关于使用 jQuery 选择焦点文本在 iPhone iPad 浏览器中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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