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網頁應用程式設計
112
|
第七章
目前的解決方式,乍聽之下會有點像是駭客的手法,但它的確可行。當使用者的滑鼠游
標滑到「瀏覽」鈕上方時,隨即在「瀏覽」鈕上方產生一個透明,而且大小、位置都和
「瀏覽」鈕一模一樣的檔案輸入欄位,用它覆蓋住「瀏覽」鈕。這麼一來,這個透明的
檔案輸入欄位,就會搶先一步擷取到所有的 click 事件,並且開啟一個瀏覽檔案總管讓
使用者點選檔案。
本書的範例程式檔
assets/ch07/jquery.browse.js
,是一個 jQuery 的外掛模組,它的作用正
是如此。只要透過 jQuery 物件實體呼叫
browseElement()
函式,就可以建立自製的檔案
瀏覽鈕。這個函式會回傳一個檔案輸入欄位,你可以替它設定一組
change
事件監聽器,
使用者一旦選取了某些檔案,就會隨即被偵測到。
var input = $("#attach").browseElement();
input.change(function(){
var files = $(this).attr("files");
});
這樣的做法,不僅能在所有的瀏覽器上正常運作,而且程式也非常簡單!
上傳檔案
XMLHttpRequest Level 2 格(
http://www.w3.org/TR/XMLHttpRequest2
)裡面有一部
分,是在定義和上傳檔案相關的功能。對使用者而言,上傳檔案一直稱不上是愉快的
操作體驗。當使用者選好要上傳的檔案之後,要先等瀏覽器重新載入網頁,然後再等上
好一段時間,檔案才會上傳完成,而且上傳的過程中也看不到上傳進度或其他的回應訊 ...
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