angular指令:弹框点击空白处隐藏

xiaoxiao2021-02-28  114

指令:

app.directive('onBlankHide',function(){ return{ restrict:'A', scope: { pop: '=' }, link: function(scope,element,attr){ element.on('click',function(e){ //阻止底层冒泡 e.stopPropagation(); angular.element('#'+scope.pop).show(); }); angular.element('body').click(function(){ angular.element('#'+scope.pop).hide(); }); angular.element('#'+scope.pop).click(function(e){ //阻止底层冒泡 e.stopPropagation(); }) } } }); 调用方法:

<a href="javascript:void(0)" on-blank-hide pop="'selLabel'" >弹框</a>pop是向指令传递的值,表示关联弹框的id名。

转载请注明原文地址: https://www.6miu.com/read-41416.html

最新回复(0)