聚焦模式窗口中的第二个元素(角度、引导 UI)



我在模态窗口中有两个按钮。当我打开窗口时,第一个按钮是聚焦的。如何将焦点更改为第二个按钮?

使用多指令时,最好使用 attr观察,因为您可能会遇到多个指令创建隔离范围的问题

app.directive('focusMe', function ($timeout) {
    return {
        link: function (scope, element, attr) {
            attr.$observe('focusMe', function (value) {
                if (value === "true") {
                    $timeout(function () {
                        element[0].focus();
                    });
                }
                else
                {
                    $timeout(function () {
                        element[0].focusout();
                    });
                 }
            });
        }
    };
});
<input name="button1" focus-me="false" type="text"/>
<input name="button2" focus-me="true" type="text"/>

最新更新