DHTML Utopia Modern Web Design Using JavaScript & DOM- P10
Thông tin tài liệu:
Nội dung trích xuất từ tài liệu:
DHTML Utopia Modern Web Design Using JavaScript & DOM- P10 Chapter 6: Forms and Validation ing country names. Some have worked around the problem of locating particular countries in these long lists by putting the more frequently-selected countries at the top,13 but this is hardly an ideal solution. It is possible to press the key that corresponds with the initial letter of an entry in the list in order to jump to that entry; repeatedly hitting that key will move between list entries that begin with that letter. This suggests an improvement: perhaps instead of keypresses triggering initial-letter searches only, they should accumulate into a string, which is matched as a whole. While typing “k,” “i,” “n” in a standard drop-down will result in a jump to the first list entry beginning with “k,” then the first beginning with “i,” then the first beginning with “n,” this could be changed so that those keypresses jump the selection to the first entry containing the string “kin.” That would probably be the United Kingdom (or the Kingdom of Tonga!), in the countries example. Functionality very similar to this is actually already present in both Safari and Firefox. Both of those browsers let you type a series of letters to match the start of an entry in a drop-down list. This example takes this feature a step further by searching for the string anywhere in the list item. And it works in Internet Explorer to boot! Unfortunately, Safari does not support handling keyboard events on drop-down lists with JavaScript. As a result, the enhancement we will undertake in this section will not apply to that browser. A number of further enhancements also suggest themselves: the current accumu- lated string should be displayed somewhere so that the user can see what they’ve entered, similar to Firefox’s “type-ahead find” feature. It should also be possible, as with type-ahead find, to press Backspace to remove the most recently-added letter from the accumulated string. Finally, after a period without typing, the accumulated string should be reset to blank to allow typing from scratch. Here’s an example HTML file containing the countries list: File: typeahead.html Type-ahead drop-down lists 13 Sometimes, developers place just one country at the top—the United States—leaving UK residents such as myself, and other non-Americans, to scroll through the ridiculously long list. Hmph. (Australi- ans don’t mind—Ed.) 160Licensed to siowchen@darke.biz Type-Ahead Drop-Down Lists Type-ahead drop-down lists Afghanistan Albania Algeria … Zaire Zambia Zimbabwe The associated JavaScript should attach an event listener to each select element in the document. Browsers offer three events for handling pressed keys: keyup, keydown, and keypress. As we saw in Chapter 3, despite being the best-supported of these properties, keypress is nonstandard, and a little limited. In particular, in some browsers it does not fire for “control” keys such as Backspace, which is required by this script. We’ll therefore use keydown for this script. In summary, we’ll create a library object as follows: File: typeahead.js var tADD = { addEvent: function(elm, evType, fn, useCapture) { … }, init: function() { … }, addKey: function(e) { … } } tADD.addEvent(window, load, tADD.init, false); This is mostly standard setup. As only a single listener is required, we’ll put it all in typeahead.js. There’s nothing else in that file. Here’s the init method: File: typeahead.js (excerpt) init: function() { if (!document.getElementsByTagName) return; var selects = document.getElementsByTa ...
Tìm kiếm theo từ khóa liên quan:
thiết kế flash giáo trình css thiết kê web kỹ thuật cắt html đồ họa máy tính 3d giáo trình photoshopGợi ý tài liệu liên quan:
-
Báo cáo thực tập: Đề tài thiết kế Web
77 trang 568 2 0 -
Đề thi thực hành môn Thiết kế Web - Trường Cao đẳng nghề Vĩnh Phúc
3 trang 267 2 0 -
vray for sketchup vietnamese PHẦN 3
10 trang 213 0 0 -
182 trang 174 0 0
-
Giáo trình CorelDRAW dành cho người mới học
48 trang 141 0 0 -
Giáo trình CorelDraw 10 - Tham khảo toàn diện: Phần 2
528 trang 133 0 0 -
Bài giảng Đồ họa máy tính: Khử mặt khuất - Ngô Quốc Việt
28 trang 127 0 0 -
MỘT SỐ ĐIỂM CẦN CHÚ Ý KHI THIẾT KẾ WEB
5 trang 113 0 0 -
GIÁO TRÌNH LẬP TRÌNH WEB_PHẦN 2_BÀI 3
3 trang 103 0 0 -
Giáo trình Nhập môn thiết kế website
58 trang 83 0 0 -
Tài liệu giảng dạy Thiết kế giao diện Web - Trường CĐ Kinh tế - Kỹ thuật Vinatex TP. HCM
88 trang 72 0 0 -
Giáo trình môn học Lý thuyết thông tin
136 trang 71 0 0 -
81 trang 68 0 0
-
112 trang 64 0 0
-
Hướng dân sử dụng Navicat để Create , Backup , Restore Database
7 trang 63 0 0 -
Giáo trình môn Kỹ thuật vi điều khiển: Thiết kế web và vi điều khiển - Chương 2
39 trang 59 0 0 -
Giáo trình Photoshop (Nghề: Lập trình máy tính-CĐ) - CĐ Cơ Giới Ninh Bình
231 trang 53 1 0 -
Bài giảng Đồ họa máy tính: Chương 3 - ThS. Trần Thị Minh Hoàn
29 trang 53 0 0 -
Giáo trình photoshop - Chương 3: Cơ bản về chỉnh sửa ảnhPhotoshop CS
19 trang 48 0 0 -
Lecture Computer graphics - Lecture 32
35 trang 46 0 0