TAILIEUCHUNG - Practical prototype and scipt.aculo.us part 19

Practical prototype and part 19: 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 97 The first argument indicates what we re listening for we want to run this code when our form is submitted. The second argument is our responder the name of the function that will get called when the form s submit event fires. Add the submitEntryForm function and the observe call to . Save go back to your browser reload the page and . . . what Error See Figure 5-3. O ffi SCentry has no properties line 20 entry .observe submit submitEntryForm Figure 5-3. Guh Of course it s defined It s right there on the page I m staring straight at it Firebug can tell us what went wrong. Select the Script tab click Options and then click Break on All Errors. This way you ll know exactly when that error happens. Reload the page. Almost immediately the page load will halt as Firebug points you to the offending line see Figure 5-4 . Figure 5-4. When Break on All Errors is on any error in your code is treated as a debugger breakpoint. 98 CHAPTER 5 EVENTS The Script tab is Firebug s JavaScript debugger. We ve just set a breakpoint pausing the evaluation of scripts and rendering in general at a certain spot. From here we can resume the page load step through functions one by one and even use Firebug s console. But right now we don t need to do any of that the screen tells us all we need to know. Notice how the viewport is empty. None of our content is there. At the time we tried to set the event the element we were referencing hadn t yet been created. This is an easy trap to fall into. Script tags are typically placed in the head of an HTML document. In the common case where a script needs to modify stuff in the body of a document it s got to wait. OK new plan we ll add our listeners when the document is fully loaded so that we can be sure that the entire DOM tree is at our disposal. Take the offending line of code and place it inside a function function addObservers entry .observe submit submitEntryForm Now we can set this function to run when

TỪ KHÓA LIÊN QUAN
TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.