使div可见或不可见取决于条件

时间:2018-05-14 09:33:38

标签: html angularjs

<div class="ddown">
    <button class="dbtn">ABC</button>
</div>       

我想在选中/取消选中复选框后进行div隐藏/显示,我该如何实现?

3 个答案:

答案 0 :(得分:3)

尝试以下代码

<input type="checkbox" ng-model="chkCondition">
<div class="ddown" ng-show="chkCondition">
    <button class="dbtn">ABC</button>
</div>

&#13;
&#13;
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
<body>

<div ng-app="">
    Check to show/Hide a div:
    <input type="checkbox" ng-model="chkCondition">
<div class="ddown" ng-show="chkCondition">
    <button class="dbtn">ABC</button>
</div>  
</body>
</html>
&#13;
&#13;
&#13;

答案 1 :(得分:2)

<强> HTML

T

答案 2 :(得分:0)

尝试使用ng-if来避免DOM元素的创建。

<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
<body>

<div ng-app="">
    <input type="checkbox" ng-model="isChecked">
<div class="ddown" ng-if="isChecked">
    <button class="dbtn">ABC</button>
</div>  
</body>
</html>