gpt4 book ai didi

javascript - 创建切换按钮行为以隐藏或显示 div

转载 作者:行者123 更新时间:2023-11-30 08:32:02 25 4
gpt4 key购买 nike

我正在尝试创建一个具有以下行为的按钮:

1) 当用户没有点击任何内容时,默认显示 ListView

2) 当用户点击Card View按钮时,List View隐藏,显示Card View

  • Card View 类设置为 button button-clear button-dark
  • List View 类设置为 button button-clear button-positive

3) 当用户点击List View按钮时,Card View隐藏,显示List View

  • Card View 类设置为 button button-clear button-positive
  • List View 类设置为 button button-clear button-dark

到目前为止,我已经设法完成了 1),但我正在努力完成 2) 和 3)。

controller.js

function StatementsController($scope, $stateParams, DummyStatementsService) {
$scope.active = true;
$scope.toggle = function(view){
if(view === 'list') {
$scope.active = true;
} else if(view === 'card') {
$scope.active = false;
}
}
}

statements.view.html

<ion-content>
<div class="row" style="margin-bottom: -1.35em" ng-controller="StatementsController">
<div class="col">
<button class="button button-clear button-dark" ng-click="toggle('list')">List View</button>
</div>
<div class="col col-right">
<button class="button button-clear button-positive" ng-click="toggle('card')">Card View</button>
</div>
</div>

<div ng-controller="StatementsController">
<!-- List view -->
<div ng-show="active">
test 1
</div>
<!-- Card view -->
<div ng-hide="active">
test 2
</div>
</div>
</ion-content>

最佳答案

由于您确实要在向按钮添加 button-darkbutton-positive 类之间切换,您可以这样做:

更新 (x2)

<ion-content> 
<div ng-controller="StatementsController"> <!-- move the ng-controller out here -->
<div class="row" style="margin-bottom: -1.35em">
<div class="col">
<button class="button button-clear"
ng-class="{'button-positive': active, 'button-dark': !active}"
ng-click="toggle('list')">List View</button>
</div>
<div class="col col-right">
<button class="button button-clear"
ng-class="{'button-positive': !active, 'button-dark': active}"
ng-click="toggle('card')">Card View</button>
</div>
</div>
<div>
<!-- List view -->
<div ng-show="active">
test 1
</div>
<!-- Card view -->
<div ng-hide="active">
test 2
</div>
</div>
</div>
</ion-content>

关于javascript - 创建切换按钮行为以隐藏或显示 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36207369/

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