Đang chuẩn bị liên kết để tải về tài liệu:
Practical prototype and scipt.aculo.us part 18
Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
Practical prototype and scipt.aculo.us part 18: The information in this book is distributed on an "as is" basis, without warranty Although every pre-caution has been taken in the preparation of this work, neither the author(s) nor Apress shall have any liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly by the information contained in this work. | CHAPTER 5 Events If you re a fan of the absurd bizarre and overcomplicated and you must be if you write JavaScript you re probably familiar with Rube Goldberg machines. Named for their cartoonist creator these ad hoc convoluted contraptions humorously obfuscate simple processes like flipping a light switch or opening a door. They paint a picture of a parallel universe where simple tasks are complicated. I m drawn to Goldberg machines because they re the opposite of how things work in everyday life. Usually we dream of an ideal world where things that seem simple actually are simple without reality stubbornly standing in the way. Browser-based event-driven interfaces should be simple. Highlight an element when the user clicks on it. Disable a submit button after a form has been submitted. But reality is harsh in the world of web development. Writing event handlers can feel like building an elaborate set of pulleys to open a window. In an unyielding quest to help client-side developers manage this complexity Prototype sports a robust event system one that makes simple things simple and complex things possible. State of the Browser Or How We Got Here I feel like a broken record browser wars lack of specifications Netscape did one thing Internet Explorer did another. It bears repeating because we re still feeling the effects 10 years later. Rather than subject you to a bland history lesson though I ll recap through code. Pre-DOM Part 1 Let s travel back in time to 1996 the heyday of Netscape 2.0 the first version to implement JavaScript. Back in the day this was how you assigned events input type submit value Post onclick postBreakfastLogEntry 91 92 CHAPTER 5 EVENTS The event assignment was just another attribute in the HTML. On its face this is a simple and straightforward way to assign events it makes simple things simple. Unfortunately it also makes complex things damn near impossible. First note that we re inside a pair of quotation marks. What if we need to use .