jquery - 使用 jQuery 选择焦点文本在 iPhone iPad 浏览器中不起作用

标签 jquery html jquery-mobile mobile-website

<分区>

我们正在为移动浏览器开发 Web 应用程序,我们希望只要输入框获得焦点,任何输入框的文本都会被选中。以下答案修复了桌面 chrome/safari 浏览器的问题。以下解决方案在 Android 浏览器上工作正常,但在 iPhone/iPad 浏览器上无效,任何解决方案..

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

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

引用:-

Selecting text on focus using jQuery not working in Safari and Chrome

最佳答案

答案在这里 不知道如何将此问题标记为重复。 Programmatically selecting text in an input field on iOS devices (mobile 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>

关于jquery - 使用 jQuery 选择焦点文本在 iPhone iPad 浏览器中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9924506/

相关文章:

jquery - Jqgrid货币格式

javascript - 将html添加到某个字符之前的所有内容

jquery - jquery-mobile collapsible展开后设置高度

android - 当我们在android应用程序中从服务器加载数据到页面时如何避免 "white screen in phonegap application"?

javascript - 如何仅在某些部分禁用输入输入?

Javascript 和 JQuery Dom 全局变量作用域

jquery - stoppropagation 无法在 jquery mobile 上工作?

html - 如何告诉谷歌我在不同域上有不同语言的网站

jquery - 将 ListView 中的 jquery 移动复选框与数据图标组合在一起

javascript - 将参数添加到 x-editable params