iOS - 手动关注输入/文本区域的解决方法 [英] iOS - Workaround for manually focusing on an input/textarea

查看:109
本文介绍了iOS - 手动关注输入/文本区域的解决方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我看到了很多关于iOS问题的主题,专注于输入/ textarea元素。 (参见此处这里)似乎iOS不会让你手动对焦在其中一个元素上,并要求它是一个真正的点击/点击以关注元素。

So I've seen a lot of threads about the iOS issue with focusing on an input/textarea element. (See here and here) It seems that iOS will not let you manually focus on one of these elements, and requires it to be a genuine tap/click to focus on the element.

我尝试模拟点击,触发点击,只需直接点击()...各种各样的事情。

I've tried simulating a click, triggering a click, simply doing click() straight away...all sorts of things.

这是我目前正在尝试实施的解决方法:

Here is my current workaround that I am trying to implement:

$scope.gotoElement = function(eID) {
    // call $anchorScroll()
    $scope.smoothScrollTo(eID).then(function() {
        clickElement('#textarea');
    });          
}

function clickElement(e) {
  $(e).on('touchstart', function() {
    //$(e).val('touchstart');
    $(e).focus();
  });

  $(e).trigger('touchstart');
}

您不必担心滚动功能,我知道这有效我已经测试了那么多。注释掉的 $(e).val('touchstart')无需更改textarea的文本,但 .focus( )在iOS上不起作用。我已经在Android设备上测试了它并且它工作正常,但在iOS上它只是没有调出键盘。有时它会开始调高键盘半秒钟然后再次消失。

You don't need to worry about the scrolling function, I know this works and I've tested that enough. The commented out $(e).val('touchstart') works with no issues to change the text of the textarea, but the .focus() does not work on iOS. I've tested this on an Android device and it works fine, but on iOS it just doesn't bring up the keyboard. Sometimes it will start to bring up the keyboard for half a second and then disappear again.

我看过其他线程,如上所述,我不能似乎弄清楚如何为此编写解决方法。

I've looked at other threads as I mentioned above, and I can't seem to figure out just how to write a workaround for this.

任何想法?

推荐答案

我也骚扰过这个问题。
我的问题通过简单的一个css属性解决了 -webkit-user-select:none 我删除了这个并且一切正常。
试试这个。

I have also harassed same this like issue. my issue solved by simple one css property that is -webkit-user-select:none I removed this and all works fine. try out this.

这篇关于iOS - 手动关注输入/文本区域的解决方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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