AngularJS学习之旅—AngularJS 事件(十四)
AngularJS学习之旅—AngularJS 事件(十四)
1、AngularJS 事件
ngClick ( 适用标签 :所有,触发事件:单击);
ngDblclick( 适用标签 :所有,触发事件:双击);
ngBlur(适用标签 : a,input,select,textarea,触发事件:失去焦点);
ngFocus(适用标签 : a,input,select,textarea,触发事件:获取焦点);
ngChange(适用标签 : a,input,select,textarea,触发事件:model更新);
ngkeydown(适用标签 : 所有,触发事件:键盘按键按下,要把$event传过去);
ngKeyup(适用标签 :大部分用在input、textarea, 但适用所有标签,触发事件:键盘按键按下并松开,但要把$event 传过去);
ngKeypress(同上);
ngMousedown(适用标签 : 所有,触发事件:鼠标按下,左右中间都会触发);
ngMouseup(适用标签 : a,input,select,textarea,触发事件:鼠标按下弹起,左右中间都会触发);
ngMouseenter(适用标签 :所有,触发事件:鼠标进入);
ngMouseleave(适用标签 :所有,触发事件:鼠标离开);
ngMousemove(适用标签 :所有,触发事件:鼠标移动);
ngMouseover(适用标签 :所有,触发事件:鼠标进入);
2、AngularJS 实例
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script src="js/angular.min.js"></script> </head> <body> <div ng-app="myApp" ng-controller="myCtrl"> <!-- ng-click 指令 --> <button ng-click="count = count + 1">点我!</button> <p>{{ count }}</p> <button ng-click="toggle()">{{text}}</button> <p ng-hide="myVar"> 名: <input type="text" ng-model="firstName"> <br> 姓名: <input type="text" ng-model="lastName"> <br> <br> Full Name: {{firstName + " " + lastName}} </p> </div> </body> </html> <script> var app = angular.module('myApp', []); app.controller('myCtrl', function ($scope) { $scope.firstName = "John"; $scope.lastName = "Doe"; $scope.flag = false; $scope.myVar = true; $scope.text = '点击可见'; $scope.toggle = function(){ $scope.myVar = !$scope.myVar; $scope.flag = !$scope.flag; $scope.text = $scope.flag ? '点击消失' : '点击可见'; } }); </script>
posted on 2019-02-11 16:15 Jamel_Song 阅读(…) 评论(…) 编辑 收藏