Javascript 弹出时,在弹出窗口中选择“聚焦关闭”按钮

Javascript 弹出时,在弹出窗口中选择“聚焦关闭”按钮,javascript,jquery,angularjs,Javascript,Jquery,Angularjs,我有一个div作为 <div id="modal" tabindex="-1" ng-show="booleanvariable" ></div> 是否有任何类似于onShow的展会活动,以便我将上述代码放在onShow活动中 谢谢, Balaji。您可以观看绑定到ng的模型显示,并在达到正确状态时触发它 $scope.$watch('isShown', function(newValue, oldValue) { if (newValue !==

我有一个div作为

     <div id="modal"   tabindex="-1" ng-show="booleanvariable" ></div>
是否有任何类似于onShow的展会活动,以便我将上述代码放在onShow活动中

谢谢,
Balaji。

您可以观看绑定到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();
            });
        }
    }
});

不完全清楚您希望在这里发生什么。@jonmrich我的意思是,我有一个打开良好的弹出窗口,但是我想在弹出窗口中聚焦关闭按钮,当弹出窗口打开时,我将在问题中详细显示,感谢Jonmrichi Brand,感谢您的回复,您是否说当ng show为真时会触发Ishown事件?,为什么因为我有很多ng show,但是我想要这种行为,当一个特定的ng show Events Shown不是一个事件时,它意味着是绑定到ng show指令的scope属性,请查看ya上的$watch函数,我尝试过,不知怎的,我的dom在这个$watch的时候似乎没有加载,+1的意思是:)您可以尝试使用$timeout来包装focus()调用,以确保在下一个周期后获得焦点。这不是最漂亮的解决方案,但它可能会奏效。非常感谢Cheeeeeers:)
$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();
            });
        }
    }
});