angularjs学习笔记—事件指令
ngClick
适用标签:所有
触发条件:单击
#html
<div ng-controller="LearnCtrl">
<div ng-click="click()">click me</div>
<button ng-click="click()">click me</button>
</div> #script
angular.module('learnModule', []) .controller('LearnCtrl', function ($scope) {
$scope.click = function () {
alert('click');
}
});
ngDblclick
适用标签:所有
触发条件:双击
#html
<div ng-controller="LearnCtrl">
<div ng-dblclick="dblclick()">click me</div>
<button ng-dblclick="dblclick()">click me</button>
</div> #script
angular.module('learnModule', []) .controller('LearnCtrl', function ($scope) {
$scope.dblclick = function () {
alert('click');
}
});
ngBlur
适用标签:
a
input
select
textarea
触发条件:失去焦点
#html
<div ng-controller="LearnCtrl">
<a href="" ng-blur="blur()">link</a> <input type="text" ng-blur="blur()"/>
<textarea cols="" rows="" ng-blur="blur()"></textarea>
<select ng-blur="blur()">
<option>----</option>
<option>jacky</option>
<option>rose</option>
</select>
</div> #script
angular.module('learnModule', []) .controller('LearnCtrl', function ($scope) {
$scope.blur = function () {
alert('blur');
}
});
ngFocus
适用标签:
a
input
select
textarea
触发条件:获取焦点
#html
<div ng-controller="LearnCtrl">
<a href="" ng-focus="focus()">link</a> <input type="text" ng-focus="focus()"/>
<textarea cols="" rows="" ng-focus="focus()"></textarea>
<select ng-focus="focus()">
<option>----</option>
<option>jacky</option>
<option>rose</option>
</select>
</div> #script
angular.module('learnModule', []) .controller('LearnCtrl', function ($scope) {
$scope.focus= function () {
alert('focus');
}
});
ngChange
适用标签:input
触发条件:model更新
输入框的内容改变并不代表model的值更新。按我的理解,一般当两个状态互相切换时,model值会更新。两个状态我称之为合法状态和不合法状态。
不合法的状态:输入的内容不符合type类型,如email类型。输入的内容不符合校验条件,如ngMinlength。不合法的状态下,model会被更新成undefined。
合法的状态:输入的内容是符合类型和校验条件的。
#html
<div ng-controller="LearnCtrl">
<input type="text" ng-model="text" ng-change="change()" ng-minlength=""/>
</div> #script
angular.module('learnModule', []) .controller('LearnCtrl', function ($scope) {
//$scope.text='';
$scope.change = function () {
alert('change');
}
});
初始化和不初始化text的条件下,change触发是不一样的哦,这里涉及到model初始化和更新机制。
ngCopy
适用标签:
a
input
select
textarea
官方api上说使用的标签是这些,我没明白a和select复制有啥子用。另外,我换个div实际上也能触发copy事件。一般常用的就是input和textarea。
触发条件:复制。鼠标右键复制和快捷键Ctrl+C都会触发。
#html
<div ng-controller="LearnCtrl">
<input type="text" ng-copy="copy()"/>
<textarea cols="" rows="" ng-copy="copy()"></textarea>
</div> #script
angular.module('learnModule', []) .controller('LearnCtrl', function ($scope) {
$scope.copy = function () {
alert('copy');
}
});
ngCut
适用标签:
a
input
select
textarea
触发条件:剪切。鼠标右键剪切和快捷键Ctrl+X都会触发。
#html
<div ng-controller="LearnCtrl">
<input type="text" ng-cut="cut()"/>
<textarea cols="" rows="" ng-cut="cut()"></textarea>
</div> #script
angular.module('learnModule', []) .controller('LearnCtrl', function ($scope) {
$scope.cut = function () {
alert('cut');
}
});
ngPaste
适用标签:
a
input
select
textarea
触发条件:粘贴。鼠标右键粘贴和快捷键Ctrl+V都会触发。
#html
<div ng-controller="LearnCtrl">
<input type="text" ng-paste="paste()"/>
<textarea cols="" rows="" ng-paste="paste()"></textarea>
</div> #script
angular.module('learnModule', []) .controller('LearnCtrl', function ($scope) {
$scope.paste = function () {
alert('paste');
}
});
ngKeydown
适用标签:所有
个人感觉还是input和textarea比较常用
触发条件:键盘按键按下
要把$event传过去,一般都是要判断按了哪个按键的。
#html
<div ng-controller="LearnCtrl">
<input type="text" ng-keydown="keydown($event)"/>
<textarea cols="" rows="" ng-keydown="keydown($event)"></textarea>
</div> #script
angular.module('learnModule', []) .controller('LearnCtrl', function ($scope) {
$scope.keydown = function ($event) {
alert($event.keyCode);
}
});
ngKeyup
适用标签:所有
个人感觉还是input和textarea比较常用
触发条件:键盘按键按下并松开
#html
<div ng-controller="LearnCtrl">
<input type="text" ng-keyup="keyup($event)"/>
<textarea cols="" rows="" ng-keyup="keyup($event)"></textarea>
</div> #script
angular.module('learnModule', []) .controller('LearnCtrl', function ($scope) {
$scope.keyup = function ($event) {
alert($event.keyCode);
}
});
ngKeypress
适用标签:所有
个人感觉还是input和textarea比较常用
触发条件:键盘按键按下
#html
<div ng-controller="LearnCtrl">
<input type="text" ng-keypress="keypress($event)"/>
<textarea cols="" rows="" ng-keypress="keypress($event)"></textarea>
</div> #script
angular.module('learnModule', []) .controller('LearnCtrl', function ($scope) {
$scope.keypress = function ($event) {
alert($event.keyCode);
}
});
keydown,keypress,keydown三者区别
引发事件的按键
非字符键不会引发 KeyPress 事件,但非字符键却可以引发 KeyDown 和 KeyUp 事件。
事件引发的时间
KeyDown 和 KeyPress 事件在按下键时发生,KeyUp 事件在释放键时发生。
事件发生的顺序
KeyDown -> KeyPress -> KeyUp。如果按一个键很久才松开,发生的事件为:KeyDown -> KeyPress -> KeyDown -> KeyPress -> KeyDown -> KeyPress -> ... -> KeyUp。
KeyDown触发后,不一定触发KeyUp,当KeyDown 按下后,拖动鼠标,那么将不会触发KeyUp事件。
KeyPress主要用来捕获数字(注意:包括Shift+数字的符号)、字母(注意:包括大小写)、小键盘等除了F1-12、SHIFT、Alt、Ctrl、Insert、Home、PgUp、Delete、End、PgDn、ScrollLock、Pause、NumLock、{菜单键}、{开始键}和方向键外的ANSI字符。
KeyDown 和KeyUp 通常可以捕获键盘除了PrScrn所有按键(这里不讨论特殊键盘的特殊键)。
KeyPress 只能捕获单个字符。
KeyDown 和KeyUp 可以捕获组合键。
KeyPress 可以捕获单个字符的大小写。
KeyDown和KeyUp 对于单个字符捕获的KeyValue 都是一个值,也就是不能判断单个字符的大小写。
KeyPress 不区分小键盘和主键盘的数字字符。
KeyDown 和KeyUp 区分小键盘和主键盘的数字字符。
其中PrScrn 按键KeyPress、KeyDown和KeyUp 都不能捕获。
ngMousedown
适用标签:所有
触发条件:鼠标按下,左右中间按下都会触发
#html
<div ng-controller="LearnCtrl">
<button ng-mousedown="mousedown($event)">button</button>
</div> #script
angular.module('learnModule', []) .controller('LearnCtrl', function ($scope) {
$scope.mousedown = function ($event) {
alert($event.which);
}
});
ngMouseup
适用标签:所有
触发条件:鼠标按下弹起,左右中间按下弹起都会触发
#html
<div ng-controller="LearnCtrl">
<button ng-mouseup="mouseup($event)">button</button>
</div> #script
angular.module('learnModule', []) .controller('LearnCtrl', function ($scope) {
$scope.mouseup = function ($event) {
alert($event.which);
}
});
ngMouseenter
适用标签:所有
触发条件:鼠标进入
#html
<div ng-controller="LearnCtrl">
<button ng-mouseenter="mouseenter()">button</button>
</div> #script
angular.module('learnModule', []) .controller('LearnCtrl', function ($scope) {
$scope.mouseenter = function () {
alert('mouseenter');
}
});
ngMouseleave
适用标签:所有
触发条件:鼠标离开
#html
<div ng-controller="LearnCtrl">
<button ng-mouseleave="mouseleave()">button</button>
</div> #script
angular.module('learnModule', []) .controller('LearnCtrl', function ($scope) {
$scope.mouseleave = function () {
alert('mouseleave');
}
});
ngMousemove
适用标签:所有
触发条件:鼠标移动
#html
<div ng-controller="LearnCtrl">
<button ng-mousemove="mousemove()">button</button>
</div> #script
angular.module('learnModule', []) .controller('LearnCtrl', function ($scope) {
$scope.mousemove = function () {
alert('mousemove');
}
});
ngMouseover
适用标签:所有
触发条件:鼠标进入
#html
<div ng-controller="LearnCtrl">
<button ng-mouseover="mouseover()">button</button>
</div> #script
angular.module('learnModule', []) .controller('LearnCtrl', function ($scope) {
$scope.mouseover= function () {
alert('mouseover');
}
});
angularjs学习笔记—事件指令的更多相关文章
- AngularJS学习笔记2——AngularJS的初始化
本文主要介绍AngularJS的自动初始化以及在必要的适合如何手动初始化. Angular <script> Tag 下面通过一小段代码来介绍推荐的自动初始化过程: <!doctyp ...
- AngularJs学习笔记--Forms
原版地址:http://code.angularjs.org/1.0.2/docs/guide/forms 控件(input.select.textarea)是用户输入数据的一种方式.Form(表单) ...
- AngularJs学习笔记--directive
原版地址:http://code.angularjs.org/1.0.2/docs/guide/directive Directive是教HTML玩一些新把戏的途径.在DOM编译期间,directiv ...
- AngularJs学习笔记--bootstrap
AngularJs学习笔记系列第一篇,希望我可以坚持写下去.本文内容主要来自 http://docs.angularjs.org/guide/ 文档的内容,但也加入些许自己的理解与尝试结果. 一.总括 ...
- AngularJs学习笔记--html compiler
原文再续,书接上回...依旧参考http://code.angularjs.org/1.0.2/docs/guide/compiler 一.总括 Angular的HTML compiler允许开发者自 ...
- AngularJs学习笔记--concepts(概念)
原版地址:http://code.angularjs.org/1.0.2/docs/guide/concepts 继续.. 一.总括 本文主要是angular组件(components)的概览,并说明 ...
- AngularJs学习笔记--Using $location
原版地址:http://code.angularjs.org/1.0.2/docs/guide/dev_guide.services.$location 一.What does it do? $loc ...
- AngularJs学习笔记--Managing Service Dependencies
原版地址:http://docs.angularjs.org/guide/dev_guide.services.managing_dependencies angular允许service将其他ser ...
- AngularJs学习笔记--I18n/L10n
原版地址:http://code.angularjs.org/1.0.2/docs/guide/i18n 一.I18n and L10n in AngularJS 1. 什么是I18n和L10n? 国 ...
随机推荐
- POJ_3009——冰球,IDS迭代加深搜索
Description On Planet MM-21, after their Olympic games this year, curling is getting popular. But th ...
- DLL模块:extern "C"的简单解析
1.揭密extern "C" extern "C"包含双重含义,从字面上即可得到:首先,被它修饰的目标是 "extern”的:其次,被它修饰的目标是 ...
- Palindrome Pairs 解答
Question Given a list of unique words, find all pairs of distinct indices (i, j) in the given list, ...
- GF(2^8)生成元
目的是找出所有GF(2^8)的生成元. 方法很简单,从2开始遍历,将每个元素都与自身相乘255次,看是否能得到1~255.若能,则是生成元. #include<iostream> #inc ...
- MyEclipse8.6下的svn插件安装
myeclipse8.6的svn插件安装 下载site-1.6.18.zip 在myeclipse8.6的MyEclipse8.6的安装目录D:/install/MyEclipse8.6/Genuit ...
- ubuntu dash
缘由:写一些脚本放在/etc/rc.loca自动执行开机启动报错 fiail to start /etc/rc.local 查找资料 缘起:ubuntu在6.0后默认bash改为了dash 导致很多 ...
- facebook分享遇到的错误解决方法
*** Terminating app due to uncaught exception 'InvalidOperationException', reason: ''App ID not foun ...
- 【C#通用类】日志记录类
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Tex ...
- volatile-java关键字
volatile的作用: 作为指令关键字,确保本条指令不会因编译器的优化而省略,且要求每次直接读值. 简单地说就是防止编译器对代码进行优化.比如如下程序: XBYTE[2]=0x55; XBYTE[2 ...
- HDU 1501 & POJ 2192 Zipper(dp记忆化搜索)
题意:给定三个串,问c串是否能由a,b串任意组合在一起组成,但注意a,b串任意组合需要保证a,b原串的顺序 例如ab,cd可组成acbd,但不能组成adcb. 分析:对字符串上的dp还是不敏感啊,虽然 ...