这是自动对焦的简单指令:
app.directive('autoFocus', function($timeout) {
return {
restrict: 'AC',
link: function(_scope, _element) {
$timeout(function(){
_element[0].focus();
}, 0);
}
};
});
但是:ぁzxswい
该指令在Chrome中运行良好,但在Firefox中不起作用。 http://jsfiddle.net/ounsqcmt/55/ 任何的想法 ?
它在firefox中显示警告:“不推荐使用getAttributeNode()。请改用getAttribute()。”
这似乎是Firefox中的一个内部问题,至少有一个警告是在version 36.00
修复的。 jQuery也提出了控制台中显示的警告问题。
https://bugzilla.mozilla.org/show_bug.cgi?id=690120
但它表明bug已经被他们的结局修复了。
这也可能既不是FireFox的问题,也不是jQuery的错误。由于DOM 4级API的重大变化,它可能是DOM接口问题。
See this stack overflow link for additional information:
var app = angular.module("App", []);
app.controller("AppCtrl", function($scope) {
})
app.directive('autoFocus', function($timeout) {
return {
restrict: 'AC',
link: function(_scope, _element) {
$timeout(function(){
window.focus()
_element[0].focus();
}, 0);
}
};
});