Skip to Content
JAVASCRIPT網頁應用程式設計
book

JAVASCRIPT網頁應用程式設計

by Alex MacCaw
January 2013
Intermediate to advanced
332 pages
5h 23m
Chinese
GoTop Information, Inc.
Content preview from JAVASCRIPT網頁應用程式設計
28
|
第二章
事件函式庫
在處理 JavaScript 的事件機制時,通常會需要使用一些現成的 JavaScript 函式庫,因為
如果不這麼做的話,就得自行處理數不清的瀏覽器相容性問題。接下來,本書將為你
介紹如何利用 jQuery 和事件機制相關的 API。當然,除了 jQuery 之外,其實還有其他
不錯的選擇,像是Prototype
http://www.prototypejs.org
)、 MooTools
http://mootools.
net
),以及 YUI
http://developer.yahoo.com/yui
)。如果想更了解這些函式庫,可以參考
它們各自的 API 文件。
jQuery API 中,有個
bind()
函式,可以建立能跨瀏覽器的事件監聽器。只要透過
jQuery 的物件實體來呼叫這個函式,並傳入兩組參數:事件名稱(eventName)、事件
處理器(handler)即可:
jQuery("#element").bind(eventName, handler);
如果想要在某個網頁元件上設定 click 事件處理器,可以這麼寫:
jQuery("#element").bind("click", function(event) {
// ...
});
jQuery 針對一些常見的事件類型(像是
click
submit
,和
mouseover
…等)提供快捷函
式。用法如下:
$("#myDiv").click(function(){
// ...
});
這裡要特別注意的是,在幫網頁元件設定事件之前,必須要確定該元件已經存在—也就 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

初めてのJavaScript 第3版 ―ES2015以降の最新ウェブ開発

初めてのJavaScript 第3版 ―ES2015以降の最新ウェブ開発

Ethan Brown, 武舎 広幸, 武舎 るみ
PHP编程:第4版

PHP编程:第4版

Kevin Tatroe, Peter MacIntyre
Strange Code

Strange Code

Ronald T. Kneusel
Perfecting Your Thinking Skills

Perfecting Your Thinking Skills

MIT Sloan Management Review

Publisher Resources

ISBN: 9789862766811