gpt4 book ai didi

javascript - AngularJS可关闭的div点击后不关闭

转载 作者:行者123 更新时间:2023-11-28 05:04:52 26 4
gpt4 key购买 nike

我正在关注 blur admin单击按钮后显示警报的 UI。但是,当我单击关闭按钮时,可关闭的警报消息并未关闭。

我希望能够关闭警报消息并打开 scope.added = false。有什么帮助吗?

这是我的代码的样子:

在 HTML 中:

  <div ng-show="added" class="alert bg-success closeable" role="alert">
<button type="button" class="close" aria-label="Close"><span
aria-hidden="true">&times;</span></button>
<strong>Added</strong> Successfully!
</div>
<div style="text-align: center">
<button type="submit" ng-click="display()"
class="btn btn-danger">add
</button>
</div>

在 JS 中:

$scope.added = false;
$scope.display= function () {
$scope.added = true;

}

谢谢

最佳答案

ng-click 添加到 X(关闭)按钮:

<button 
type="button"
class="close"
aria-label="Close"
ng-click="close()">
<span aria-hidden="true">
&times;
</span>
</button>

然后将close()函数添加到 Controller :

$scope.close = function(){
$scope.added = false;
}

关于javascript - AngularJS可关闭的div点击后不关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41840030/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com