在元素焦点上打开IOS键盘

时间:2014-11-11 21:40:14

标签: jquery ios angularjs angularjs-directive

我正在使用指令在用户点击链接时触发焦点输入字段。除了IOS之外,它在任何地方都可以正常工作。它没有在焦点上打开ios设备(iphone / ipad)上的键盘。它在输入周围添加了蓝色边框,表明它是聚焦的。如何在焦点上打开ios设备中的键盘?

HTML

 <a data-mya-triggerfocus="something" >Something</a>
 <input name="something" id="something" />

JS

   angular.module('app').directive('myaTriggerfocus', function ($timeout) {
    return {
        link: function (scope, element, attrs) {
            element.bind('click', function () {
                $timeout(function () {
                    var otherElement = document.querySelector('#' + attrs.myaTriggerfocus);  
                        otherElement.focus();      
                });
            });
        }
    };
});

2 个答案:

答案 0 :(得分:0)

输入&#34;类型&#34;属性帮助?

<a data-mya-triggerfocus="something" >Something</a>
<input name="something" **type="text"** id="something" />

要显示数字键盘,您可以尝试:

<input type="text" pattern="[0-9]*">

我想回忆一下Apple的文档建议 - 将模式属性的值设置为&#34; [0-9] *&#34;或&#34; d *&#34;为了打开数字键盘。不确定它是否与此相关。只是说...

答案 1 :(得分:0)

尝试添加:

<preference name="KeyboardDisplayRequiresUserAction" value="false"/>

在您的app的config.xml文件中。

(根据ios的定义)

相关问题