javascript - AngularJS, stop the a href? -
i using angularjs. want realize type onediv
button, hide `onediv.' then, google every time. don't want go google. how stop "a href"?
the question named "how preventdefault on anchor tags?" question. in question, use angularjs, new question due use angularjs.
<style> .content { width: 500px; height: 400px; background-color: green; } .one { width: 100px; height: 100px; background-color: black; } .two { width: 100px; height: 100px; background-color: yellow; } </style> <body ng-app="app" ng-controller="controller"> <div class="content"> <div ng-show="!onehide" class="one"> <a href="http://www.google.com"> <button ng-click="oneclickfun()">xxxx</button> </a> </div> <div class="two"> <a href="www.google.com"> </a> </div> </div> <script> var app = angular.module('app',[]); app.controller('controller',['$scope', function ($scope) { $scope.onehide = false; $scope.oneclickfun = function () { $scope.onehide = true; } }]) </script> </body>
who can modify code hide onediv
only?
attach $event oneclickfun() called function , add preventdefault() in controller function.
try this:
<style> .content { width: 500px; height: 400px; background-color: green; } .one { width: 100px; height: 100px; background-color: black; } .two { width: 100px; height: 100px; background-color: yellow; } </style> <body ng-app="app" ng-controller="controller"> <div class="content"> <div ng-show="!onehide" class="one"> <a href="http://www.google.com"> <button ng-click="oneclickfun($event)">xxxx</button> </a> </div> <div class="two"> <a href="www.google.com"> </a> </div> </div> <script> var app = angular.module('app',[]); app.controller('controller',['$scope', function ($scope) { $scope.onehide = false; $scope.oneclickfun = function (e) { e.preventdefault(); $scope.onehide = true; } }]) </script> </body>
hope you.
Comments
Post a Comment