当弹出时,焦点关闭按钮在弹出窗口中

focus close button in the popup when it is popped up

本文关键字:窗口 关闭按钮 焦点      更新时间:2023-09-26

我有一个div作为

     <div id="modal"   tabindex="-1" ng-show="booleanvariable" ></div>

ng show为true时,我显示,但我在div下有关闭按钮,当显示div时需要聚焦。我们可以使用

      $timeout(function() 
         {
                $('.close').focus();
         }, 5000);

是否有类似onShow的显示事件,以便我将上述代码放在onShow事件中。

谢谢,巴拉吉。

您可以观看绑定到ng的模型显示,并在达到正确状态时触发它。

$scope.$watch('isShown', function(newValue, oldValue) {
    if (newValue !== oldValue) {
        $log.log('Changed!');
        if(newValue === true) {
            angular.element('.close').focus();
            // or you might have to wrap it with $timeout
            $timeout(function(){
                angular.element('.close').focus();
            });
        }
    }
});