Events and Event Handling
事件和事件处理
引用
The original event model: all js-enabled browsers
The standard event model: all modern explorer except IE
The Internet Explorer event model: IE
In the original event model, an event is an abstraction internal to the web browser, and JavaScript code cannot manipulate an event directly. When we speak of an event type in the original event model, what we really mean is the name of the event handler that is invoked in response to the event.
Semantic events, such as onsubmit and onchange, are almost always device-independent events: all modern browsers allow users to manipulate HTML forms using the mouse or keyboard traversal. The events that have the word "mouse" or "key" in them are clearly device-dependent events.
Note that the onclick event can be considered a device-independent event. It is not mouse-dependent because keyboard activation of form controls and hyperlinks also generates this event.
三类事件模型:
原始事件模型——所有启用JS的浏览器
标准模型——所有除IE以外的现代浏览器
IE事件模型——IE
在原始事件模型中,我们并不能操作事件对象本身。我们在这个模型中对事件名称的称呼多半是事件处理函数的名字。事件的内部情况完全被浏览器给抽象了。
事件又可以分为与设备依赖的事件和与设备非依赖的事件;具有语义性的事件,例如onsubmit、onchange等都是与设备无关的;而有一些例如onmouseover的事件则是与设备依赖的。
但onclick可以看做一个不依赖于设备的事件,因为键盘的点击也可以在超链接或表单元素上产生这个事件。
Event Handlers as Attributes
作为特性的事件句柄
<form action="processform.cgi" onsubmit="return validateForm( );">
Event Handlers as Properties
作为属性的事件句柄
document.f1.b1.onclick=function( ) { alert('Thanks!'); };
引用
Because the values of JavaScript event handler properties are functions, you can use JavaScript to invoke event handler functions directly.
Note, however, that invoking an event handler is not a way to simulate what happens when the event actually occurs.
by adding a handler for each hyperlink, it overwrites any onclick handlers that were already defined for those hyperlinks.
因为JS的事件处理函数是一个属性值,因此可以直接调用事件处理函数本身。
但这并不能模拟事件发生本身。
当你再次为某个超链接的onlcikc句柄添加时间处理函数,那么也就重载了之前指定的事件处理函数。
Event Handler Return Values
事件处理函数的返回值
引用
Generally, if the web browser performs some kind of default action in response to an event, you can return false to prevent the browser from performing that action.
There is one exception to the rule about returning false to cancel: when the user moves the mouse over a hyperlink, the browser's default action is to display the link's URL in the status line.
most modern browsers consider the ability to hide the destination of a link to be a security hole and have disabled it.
通常,如果浏览器对某个事件有默认多做,那么返回false就会取消那个默认多做。但也有一个例外,你不能在鼠标滑过一个超链接时通过返回false来取消提示信息的显示。因为大多数浏览器认为如果这样做了就是不安全的,所以就禁止了以下这种行为:
<a href="help.htm" onmouseover="window.status='Help!!'; return true;">Help</a>
分享到:
相关推荐
JavaScript高级编程 pdfJavaScript高级编程 pdfJavaScript高级编程 pdfJavaScript高级编程 pdf
javascript函数式编程 javascript函数式编程 javascript函数式编程
JavaScript DOM编程艺术 --全
javascript网络编程基础教程,javascript网络编程基础教程,javascript网络编程基础教程
经典之作《javascript dom编程艺术》源码。通过一个实际案例,讲述了原生的javascript操作dom的使用方法,以及操作dom中应该注意的一些事项。
JavaScriptDOM编程艺术(第2版)PDF版本下载
JavaScript一种直译式脚本语言,是一种动态类型、弱类型、基于原型的语言,内置支持类型。它的解释器被称为JavaScript引擎,为浏览器的一部分,广泛用于客户端的脚本语言,最早是在HTML(标准通用标记语言下的一个...
本 书在简洁明快地讲述JavaScript和DOM的基本知识之后,通过几个实例演示了专业水准的网页开发技术,透彻阐述了平稳退化等一批至关重要的 JavaScript编程原则和最佳实践,并全面探讨了HTML5以及jQuery等JavaScript库...
Javscript高性能编程+Javascript异步编程 高清晰PDF
资源名称:JavaScript高效图形编程内容简介:《Javascript高效图形编程》是一本具有很强实操性的Javascript图书,全书共分10章,涵盖的主要内容有:Javascript的面向对象机制、Javascript...
JavaScript异步编程 设计快速响应的网络应用
第5章 JavaScript编程技术 5.1 JavaScript编程基础 5.1.1 JavaScript简介 5.1.2 Javascript的使用方法 5.1.3 语法规则 5.1.4 运算符和表达式 5.1.5 函数 5.1.6流程控制 5.1.7 事件处理 5.2 JavaScript对象编程 5.2.1...
从颇具深度的JavaScript语言基础到作用域(链),从引用类型到面向对象编程,从极其灵活的匿名函数到闭包的内部机制,从浏览器对象模型(BOM)、文档对象模型(DOM)到基于事件的Web脚本设计,从XML(E4X)到Ajax及JSON,从...
javascript高效编程和函数式编程指南书籍PDF,适合深入学习javascript
JavaScript 编程精解 中文第三版 JavaScript 编程精解 中文第三版
JavaScriptDom编程艺术,一本很好的前端书籍,有兴趣的可以看看
JavaScript DOM编程艺术 经典书籍
Javascript编程语言的编程规范,主要是讲解Javascript编程语言的编程规范,没有什么javascript的知识,都是一些规范
第一章 javascript语言概述 第二章 JavaScript语言基础 第三章 JavaScript事件处理 第四章 JavaScript基于对象编程 第六章 string,math,array等数据对象 第七章 window及相关顶级对象 第八章 document对象
JavaScript DOM编程艺术,高清资源,无比经典,值得拥有