2017-02-24 81 views
10

當我在桌面或Android設備上運行應用程序時,輸入焦點工作正常。但它不適用於ios 10 Safari。我正在使用angularjs。ios 10自動對焦不對焦輸入

$timeout(function() { 
    var input = $element.find('.my-input-box')[0]; 
    input.focus(); 
}, 500); 
+0

$超時(函數(){。 $( '#someID')聚焦();} ,500);試試這個 –

+0

檢查你的輸入元素是在DOM還是NOT? –

+0

它在DOM中,這就是爲什麼在桌面和Android上工作 – Rohit

回答

3

由於您使用的是angularjs,因此您應該嘗試在角度上查找您的解決方案。

您是否嘗試過使用ngFocus

我猜它可能是這樣的:

HTML:

<input ng-focus="YourVariable"> 

並設置YourVariable爲True。

0

我發現這個https://github.com/angular/material/issues/10080

可能是這對您有所幫助。

此鏈接表示可能是事件/手勢問題。

+0

或者您可以嘗試: - http://stackoverflow.com/questions/14859266/input-autofocus-attribute?rq=1 –

0

無需查找元素。您可以添加指令。

yourApp.directive('autofocus', ['$timeout', function($timeout) { 
    return { 
    restrict: 'A', 
    link : function($scope, $element) { 
     $timeout(function() { 
     $element[0].focus(); 
     }); 
    } 
    } 
}]); 

和使用,如: -

<input autofocus type="text"/> 

Here is working example