我有一个工作代码来关闭使用jQuery的自定义弹出窗口,但我想要一个使用AngularJS而不是jQuery的解决方案。 任何人都可以帮助我在AngularJS中找到this.closest()
。AngularJS中最接近的父选择器
我想隐藏.popOverlay
点击使用AngularJS的.popClose
,而不是jQuery。我不想使用perticular class/id becoz我有很多像这样的弹出窗口,我想为它们提供一个通用的解决方案。
这是我工作的jQuery代码:
function popClose(e)
{
\t $(e).closest('.popOverlay').fadeOut('slow');
}
.popOverlay { background:rgba(0,0,0,.5); width:100%; height:100%; overflow-y:auto; position:fixed; left:0; top:0;}
.popBox { background:#fff; border-radius:5px; position:relative; width:400px; max-width:90%; padding:20px; margin-left:auto; margin-right:auto; margin-top:50px;}
.popClose { display:inline-block; position:absolute; top:5px; right:10px; cursor:pointer; color:#f00; font:bold 16px Arial, Helvetica, sans-serif;}
.heading { color:#0077c8; font:bold 16px Arial, Helvetica, sans-serif; margin-top:0;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="popOverlay">
\t <div class="popBox">
\t \t <a class="popClose" onClick="popClose(this)">x</a>
\t \t <h3 class="blue-heading">This is a custom popup.</h3>
\t </div>
</div>
您想要Angular solution:'ngIf'。 – dfsq
是的,我想使用AngularJS而不是jQuery来点击'.popClose'来隐藏'.popOverlay'。也可以考虑我不想使用perticular class/id becoz我有很多喜欢它的弹出窗口,我想为它们提供通用的解决方案。 –