【问题标题】:Is it possible to select all input text on iphone device when focus / click?焦点/单击时是否可以选择iphone设备上的所有输入文本?
【发布时间】:2012-05-14 05:00:02
【问题描述】:

焦点/点击时是否可以选择iphone设备上的所有输入文本?

通常用于浏览器环境:

$('input').bind("click focus", function() {
$(this).select();
});

这适用于桌面浏览器,但对于 iphone 和可能的其他移动设备似乎无响应。

【问题讨论】:

标签: jquery iphone select jquery-mobile


【解决方案1】:

基本上你必须重新排列事件焦点,然后单击,然后触摸开始

$('#myID').on('focus click touchstart', function(e){
$(this).get(0).setSelectionRange(0,9999);
//$(this).css("color", "blue"); FUBAR
e.preventDefault();
});

【讨论】:

    【解决方案2】:

    设置一个(小)超时最适合我: iOS键盘似乎是在委托或其他东西中调用的,因为它不断失去我的焦点事件才能选择东西。由于同样的原因,select() 不起作用。

    我是这样解决的:

    function focusMe(vitem) {
        window.setTimeout(function() { 
          vitem.setSelectionRange(0, 9999);
        }, 10);
    }
    
    <input onfocus="focusMe(this)" />
    

    【讨论】:

      【解决方案3】:
      $('input[type="text"]').on('focus',function(){
          $(this).get(0).selectionStart=0;
          $(this).get(0).selectionEnd=999;
      })
      

      我最初找到了这个信息here,还有其他人尝试过的事情已经达到了结果。

      【讨论】:

      • $(this).get(0)this 完全相同。
      • 确实如此。我是多么的多余。
      【解决方案4】:

      我会使用这样的东西:

      $('input').live("click", function() {
          $('input').each(function(){
              $(this).select();
          });
      });
      $('input').live("focus", function() {
          $('input').each(function(){
              $(this).select();
          });
      });
      

      【讨论】:

        猜你喜欢
        • 2017-09-26
        • 2013-02-06
        • 2021-04-16
        • 2019-04-27
        • 2011-05-03
        • 1970-01-01
        • 2013-05-13
        • 2019-07-06
        • 1970-01-01
        相关资源
        最近更新 更多