加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

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

发布时间:2020-12-17 16:57:44 所属栏目:安全 来源:网络整理
导读:在我的angular.js学习项目中,我想隐藏一个div,当我点击一个按钮时显示另一个div. 在这段代码中,我希望第一个div隐藏在点击(甚至销毁?)和第二个div显示. 基本上我想要在我的应用程序中从第1页到第2页的用户体验. 我该如何实现这一目标? 的index.html ion-co
在我的angular.js学习项目中,我想隐藏一个div,当我点击一个按钮时显示另一个div.
在这段代码中,我希望第一个div隐藏在点击(甚至销毁?)和第二个div显示.
基本上我想要在我的应用程序中从第1页到第2页的用户体验.
我该如何实现这一目标?

的index.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>

controllers.js

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

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

当我运行页面时,我看到“卡2”,当我点击按钮时没有任何反应.
我想看到的是“卡1”并且当我点击按钮时它切换到“卡2”…

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

解决方法

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;
    }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读