JavaScript的事件
fortunate 幸运的、幸运的人;
词根:fort:门
上帝给你开了个门缝 -> 幸运的人
幸运女神脸被头发遮住,后脑没有头发, 表示幸运女神来时你认不出来,机会走了你抓不住。
There are many different types of events that can occur.
词根:fort:门
上帝给你开了个门缝 -> 幸运的人
幸运女神脸被头发遮住,后脑没有头发, 表示幸运女神来时你认不出来,机会走了你抓不住。
There are many different types of events that can occur.
- The user selects a certain element or hovers the cursor over a certain element.(选中元素,光标over元素)
- The user chooses a key on the keyboard.(键盘按键)
- The user resizes or closes the browser window.(用户修改和关闭browser窗口)
- A web page finishes loading.(web page 加载完成)
- A form is submitted.(表单提交)
- A video is played, paused, or finishes.(视频被播放,暂停或完成)
- An error occurs.(错误发生)
You can gather from this (and from glancing at the MDN Event reference 这里是全部事件列表) that there are a lot of events that can be responded to.
每个可用的事件都有一个event handler(事件处理者),a block of code ( usually a javascritp function that you as a programmer create) that runs when the event fires.
当这么一个区块代码被定义后被响应事件, registering an event handler.
Note: 每个event handlers, 通常也被称为 event listeners -- they are pretty much interchangeable for our purposes, although strictly speaking, the work together.
The listener listens out for the event happening, and the handler is the code that is run in response to it happening.
Note: Web events are not part of the core JavaScript language — they are defined as part of the APIs built into the browser.
web事件不是JavaScript核心,它们是浏览器的APIs
Node.js event model HTTP connect event docs WebExtensions.
You don't need to understand anything about other such environments at this stage in your learning; we just wanted to make it clear that events can differ in different programming environments.
当这么一个区块代码被定义后被响应事件, registering an event handler.
Note: 每个event handlers, 通常也被称为 event listeners -- they are pretty much interchangeable for our purposes, although strictly speaking, the work together.
The listener listens out for the event happening, and the handler is the code that is run in response to it happening.
Note: Web events are not part of the core JavaScript language — they are defined as part of the APIs built into the browser.
web事件不是JavaScript核心,它们是浏览器的APIs
Node.js event model HTTP connect event docs WebExtensions.
You don't need to understand anything about other such environments at this stage in your learning; we just wanted to make it clear that events can differ in different programming environments.
fired 自定义事件
function fireEvent(name, target, param1, param2) { //Ready: create a generic event var evt = document.createEvent("Events") //Aim: initialize it to be the event we want evt.initEvent(name, true, true); //true for can bubble, true for cancelable evt.param1 = param1; evt.param2 = param2; //FIRE! target.dispatchEvent(evt); } function foobar(ev) { alert("foobar" + ' ' + ev.param1 + ' ' + event.param2); } function testEvents(param1) { window.addEventListener("foobar", foobar, false); //false to get it in bubble not capture. fireEvent("foobar", document, 'test', param1); }
阅读量: 491
发布于:
修改于:
发布于:
修改于: