我试图通过onclick触发器将焦点设置在文本框上,但它似乎无法在我的离子角度实现中工作。如果我把它从阴道和离子
中取出来,它就有效这是模板
<ion-view title="Create">
<ion-content class="has-header">
<div>
<input type="text" placeholder="focus here" id="test" />
<button ng-click="test()">TEST</button>
</div>
</ion-content>
</ion-view>
和js
$scope.test = function(){
document.getElementById('test').focus();
};
答案 0 :(得分:11)
我在论坛上找到了答案: http://forum.ionicframework.com/t/focus-method-doesnt-work-on-input-textarea-etc/5606/14
原来你需要添加Ionic Keyboard插件并在config.xml中添加这些首选项:
<preference name="KeyboardDisplayRequiresUserAction" value="false" />
<feature name="Keyboard">
<param name="ios-package" value="IonicKeyboard" onload="true" />
</feature>
之后,focus()函数将起作用。
答案 1 :(得分:6)
对我来说,最简单快捷的方法如下:
{{1}}