gpt4 book ai didi

angularjs - 如何通过单击按钮隐藏div?

转载 作者:行者123 更新时间:2023-12-01 05:09:54 24 4
gpt4 key购买 nike

在我的 angular.js 学习项目中,我想在单击按钮时隐藏一个 div 并显示另一个。
在这段代码中,我希望第一个 div 在点击时隐藏(甚至被销毁?)并显示第二个 div。
基本上我想要在我的应用程序中从第 1 页到第 2 页的用户体验。
我该如何做到这一点?

索引.html

  <ion-content ng-controller="StartpageCtrl">

<div class="list card" id="startCard" ng-show="showstartCard">
<div class="item item-image item item-text-wrap">
Card 1
</div>
</div>
<div class="list card" id="secondCard" ng-show="showsecondCard">
<div class="item item-image item item-text-wrap">
Card 2
</div>
</div>

<button ng-click="hideCard()" class="button button-full button-calm button icon-right ion-chevron-right">
Start now
</button>

</ion-content>

Controller .js
.controller("StartpageCtrl", funcion($scope){
$scope.showstartCard = true;
$scope.showsecondCard = false;

$scope.hideCard = function() {
$scope.showstartCard = false;
$scope.showsecondCard = true;
};
});

当我运行该页面时,我看到“卡片 2”,而当我单击按钮时没有任何 react 。
我想看到的是“卡片 1”,当我点击按钮时它会切换到“卡片 2”......

已解决
我忘记在 app.js angular.module 以及 index.html 中的 script 标签中添加对controllers.js的引用。它现在工作正常。

最佳答案

Using angular:   
HTML file:
<td><a href="#" ng-click="showDetails =! showDetails">Source Doc..</a>
<div id="mydiv" ng-show="showDetails">
<div id="mydiv-container">
<div id="mydiv-content">
<a href="#" ng-click="showDetails =! showDetails">Close</a>
<br>
hello
</div>
</div>
</div>

</td>



css file:
body {
height: 100%;
background-color: #F0F0F0;
font-family: Arial, sans-serif;
}
#mydiv {
width: 100%;
height: 100%;
overflow: hidden;
left: 100px;
top: 150px;
position: absolute;
opacity: 0.95;

}
#mydiv-container {
margin-left: auto;
margin-right: auto;
}
#mydiv-content {
width: 70%;
padding: 20px;
background-color: white;
border: 1px solid #6089F7;
}
a {
color: #5874BF;
text-decoration: none;
}
a:hover {
color: #112763;
}

关于angularjs - 如何通过单击按钮隐藏div?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25769019/

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