JavaScript

超轻量级php框架startmvc

Angular实现点击按钮控制隐藏和显示功能示例

更新时间:2020-06-21 13:06:01 作者:startmvc
本文实例讲述了Angular实现点击按钮控制隐藏和显示功能。分享给大家供大家参考,具体如

本文实例讲述了Angular实现点击按钮控制隐藏和显示功能。分享给大家供大家参考,具体如下:

先来看看运行效果:

具体代码如下:


<!DOCTYPE html>
<html lang="en">
<head>
 <meta charset="UTF-8">
 <title>www.jb51.net Angular显示隐藏</title>
 <style>
 .box{
 width: 100px;
 height: 100px;
 background: red;
 }
 </style>
 <script src="angular.min.js"></script>
 <script>
 var myapp=angular.module("myapp",[]);
 myapp.controller("myCtrl",function ($scope) {
 $scope.show=true;
 $scope.fun=function () {
 $scope.show=!$scope.show;
 console.log($scope.show);
 }
 $scope.hide=true;
 $scope.func=function () {
 $scope.hide=!$scope.hide;
 }
 })
 </script>
</head>
<body ng-app="myapp" ng-controller="myCtrl">
<div class="box"ng-show="show"></div>
<button ng-click="fun()">点击切换</button>
<div ng-class="{box:hide}"></div>
<button ng-click="func()">按钮</button>
</body>
</html>

Angular 点击按钮 控制 隐藏 显示