2

我从一个按钮调用以下内容:

var d = $dialog.dialog({dialogFade: false, modal:true, backgroundClick: false}); d.open('html/xyz.html', 'xyzController');

除了对话框没有获得焦点外,一切正常。如果我们 TAB,它会将其视为页面末尾的元素。有没有办法让对话成为焦点???我尝试了所有我能找到的解决方案,但没有成功。

谢谢

4

1 回答 1

0

您可以使用指令在任何元素上设置焦点:

MyApp.directive('CustomSetFocus', [function () {
    return {
        restrict: 'A',
        link: function (scope, element, attrs, controller) {
            scope.$watch(attrs.customSetFocus, function (newValue, oldValue) {
                if (newValue === true) {                        
                        element[0].focus();                        
                }
            });
        }
    };
}]);

然后你可以像这样触发它:

<input type="text" id="whatever" custom-set-focus="true"/>

或者,您可以在控制器中设置一个范围变量来触发焦点,可能在 intialize() 函数或类似的东西中:

<input type="text" id="whatever" custom-set-focus="someScopeVariable"/>
于 2013-10-03T17:11:03.323 回答