Angular实现点击按钮控制隐藏和显示功能示例
当爱0201 人气:0本文实例讲述了Angular实现点击按钮控制隐藏和显示功能。分享给大家供大家参考,具体如下:
先来看看运行效果:
具体代码如下:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>www.qb5200.com 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>
希望本文所述对大家AngularJS程序设计有所帮助。
加载全部内容