AngularJS入门(10)-Angular事件
来源:互联网 发布:matlab 2017b mac 编辑:程序博客网 时间:2024/05/02 00:31
这一篇博客为大家介绍一下AngularJS为我们提供的事件指令。
ngBlur
<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title></title> <script src="angular.min.js" type="text/javascript"></script> <script type="text/javascript"> angular.module("MyApp", []).controller("MyCtrl", function($scope) { $scope.blur=function(msg){ alert(msg); }; }); </script> </head> <body ng-app="MyApp" ng-controller="MyCtrl"> <input ng-blur="blur('button1 blur')" type="button" value="button1" /> </body></html>
ngChange
<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title></title> <script src="angular.min.js" type="text/javascript"></script> <script type="text/javascript"> angular.module("MyApp", []).controller("MyCtrl", function($scope) { $scope.counter = 0; $scope.change = function() { $scope.counter++; }; }); </script> </head> <body ng-app="MyApp" ng-controller="MyCtrl"> <input type="checkbox" ng-model="confirmed" ng-change="change()" id="ng-change-example1" /> <label for="ng-change-example1">Confirmed</label><br /> <tt>counter = {{counter}}</tt><br/> </body></html>
ngClick
<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title></title> <script src="angular.min.js" type="text/javascript"></script> <script type="text/javascript"> angular.module("MyApp", []).controller("MyCtrl", function($scope) { $scope.count = 0; }); </script> </head> <body ng-app="MyApp" ng-controller="MyCtrl"> <button ng-click="count = count + 1">Increment</button> <span>count: {{count}}</span> </body></html>
ngCopy
<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title></title> <script src="angular.min.js" type="text/javascript"></script> <script type="text/javascript"> angular.module("MyApp", []).controller("MyCtrl", function($scope) { $scope.copied = false; $scope.value = 'copy me'; }); </script> </head> <body ng-app="MyApp" ng-controller="MyCtrl"> <input ng-copy="copied=true" ng-model="value"> copied: {{copied}} </body></html>
ngCut
<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title></title> <script src="angular.min.js" type="text/javascript"></script> <script type="text/javascript"> angular.module("MyApp", []).controller("MyCtrl", function($scope) { $scope.cut = false; $scope.value = 'cut me'; }); </script> </head> <body ng-app="MyApp" ng-controller="MyCtrl"> <input ng-cut="cut=true" ng-model="value"> cut: {{cut}} </body></html>
ngDblclick
<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title></title> <script src="angular.min.js" type="text/javascript"></script> <script type="text/javascript"> angular.module("MyApp", []).controller("MyCtrl", function($scope) { $scope.count = 0; }); </script> </head> <body ng-app="MyApp" ng-controller="MyCtrl"> <button ng-dblclick="count = count + 1"> Increment (on double click) </button> count: {{count}} </body></html>
ngKeydown
<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title></title> <script src="angular.min.js" type="text/javascript"></script> <script type="text/javascript"> angular.module("MyApp", []).controller("MyCtrl", function($scope) { $scope.count = 0; }); </script> </head> <body ng-app="MyApp" ng-controller="MyCtrl"> <input ng-keydown="count = count + 1"> key down count: {{count}} </body></html>
ngKeypress
<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title></title> <script src="angular.min.js" type="text/javascript"></script> <script type="text/javascript"> angular.module("MyApp", []).controller("MyCtrl", function($scope) { $scope.count = 0; }); </script> </head> <body ng-app="MyApp" ng-controller="MyCtrl"> <input ng-keypress="count = count + 1"> key press count: {{count}} </body></html>
ngKeyup
<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title></title> <script src="angular.min.js" type="text/javascript"></script> <script type="text/javascript"> angular.module("MyApp", []).controller("MyCtrl", function($scope) { $scope.count = 0; }); </script> </head> <body ng-app="MyApp" ng-controller="MyCtrl"> <p>Typing in the input box below updates the key count</p> <input ng-keyup="count = count + 1"> key up count: {{count}} <p>Typing in the input box below updates the keycode</p> <input ng-keyup="event=$event"> <p>event keyCode: {{ event.keyCode }}</p> <p>event altKey: {{ event.altKey }}</p> </body></html>
ngMousedown
<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title></title> <script src="angular.min.js" type="text/javascript"></script> <script type="text/javascript"> angular.module("MyApp", []).controller("MyCtrl", function($scope) { $scope.count = 0; }); </script> </head> <body ng-app="MyApp" ng-controller="MyCtrl"> <button ng-mousedown="count = count + 1"> Increment (on mouse down) </button> count: {{count}} </body></html>
ngMouseenter
<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title></title> <script src="angular.min.js" type="text/javascript"></script> <script type="text/javascript"> angular.module("MyApp", []).controller("MyCtrl", function($scope) { $scope.count = 0; }); </script> </head> <body ng-app="MyApp" ng-controller="MyCtrl"> <button ng-mouseenter="count = count + 1"> Increment (when mouse enters) </button> count: {{count}} </body></html>
ngMouseleave
<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title></title> <script src="angular.min.js" type="text/javascript"></script> <script type="text/javascript"> angular.module("MyApp", []).controller("MyCtrl", function($scope) { $scope.count = 0; }); </script> </head> <body ng-app="MyApp" ng-controller="MyCtrl"> <button ng-mouseleave="count = count + 1"> Increment (when mouse leaves) </button> count: {{count}} </body></html>
ngMousemove
<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title></title> <script src="angular.min.js" type="text/javascript"></script> <script type="text/javascript"> angular.module("MyApp", []).controller("MyCtrl", function($scope) { $scope.count = 0; }); </script> </head> <body ng-app="MyApp" ng-controller="MyCtrl"> <button ng-mousemove="count = count + 1"> Increment (when mouse moves) </button> count: {{count}} </body></html>
ngMouseover
<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title></title> <script src="angular.min.js" type="text/javascript"></script> <script type="text/javascript"> angular.module("MyApp", []).controller("MyCtrl", function($scope) { $scope.count = 0; }); </script> </head> <body ng-app="MyApp" ng-controller="MyCtrl"> <button ng-mouseover="count = count + 1"> Increment (when mouse is over) </button> count: {{count}} </body></html>
ngMouseup
<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title></title> <script src="angular.min.js" type="text/javascript"></script> <script type="text/javascript"> angular.module("MyApp", []).controller("MyCtrl", function($scope) { $scope.count = 0; }); </script> </head> <body ng-app="MyApp" ng-controller="MyCtrl"> <button ng-mouseup="count = count + 1"> Increment (on mouse up) </button> count: {{count}} </body></html>
ngPaste
<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title></title> <script src="angular.min.js" type="text/javascript"></script> <script type="text/javascript"> angular.module("MyApp", []).controller("MyCtrl", function($scope) { $scope.paste = false; }); </script> </head> <body ng-app="MyApp" ng-controller="MyCtrl"> <input ng-paste="paste=true" placeholder='paste here'> pasted: {{paste}} </body></html>
0 0
- AngularJS入门(10)-Angular事件
- AngularJS入门(10)-Angular服务总结
- AngularJS入门(3)-Angular表达式
- AngularJS入门(4)-Angular指令
- AngularJS入门(6)-Angular控制器
- AngularJS入门(7)-Angular过滤器
- AngularJS入门(8)-Angular服务
- AngularJS入门(5)-Angular作用域($Scope)
- AngularJS入门之Angular内置指令
- angular js 入门2 $watch 监听事件
- AngularJs angular.injector、angular.module
- [AngularJS面面观] 11. scope事件机制 - 事件系统在Angular框架中的应用
- angular事件
- Angular 事件
- AngularJs angular.element
- 没时间解释了,快上车!Angular入门第二讲:AngularJs入门之ontroller控制器。
- AngularJS入门教程10:事件处理器
- AngularJS(九)ng-click(事件),angular.module 函数,表单,输入验证
- 维护篇(5.2)-08. 批量命令操作 ❀ 飞塔 (Fortinet) 防火墙
- 《将博客搬至CSDN》
- 动态include与静态include的区别
- 深入字节码 -- 计算方法执行时间(ONE APM基础原理窥探)
- 【前端笔试题】数组去重
- AngularJS入门(10)-Angular事件
- 一部分常用的正则表达式代码
- 【C语言】顺序表并集与归并
- 第10周 项目2- 二叉树遍历的递归算法
- Android DrawText 基线的确定问题
- svn合并的一些坑
- path与classpath区别
- 第10周项目3-利用二叉树遍历思想解决问题
- 单例模式、双检测锁定DCL、volatile(转)