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

Practical prototype and part 25: 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. | 134 CHAPTER 6 WORKING WITH THE DOM Now append each cell to the row. tdl td2 td3 .and append the row to the table body. cities .down tbody .insert tr bottom Three times as many lines As is often the case one approach is easy but sloppy and the other is harder but more correct. Can t we split the difference First create the row. var tr new Element tr class total Next create each cell and append it on the fly. new Element td .update Total new Element td class number .update totalPopulation new Element td class code Now append the row to the table body. cities .down tbody .insert tr bottom We haven t talked about this technique yet but it ought to seem familiar anyway. The glue in the middle the new Element part takes a tag name as its first argument creates that element calls on it to give it the Prototype instance methods and then returns the element. The rest of it is stuff we ve already covered The optional second argument to Element is an object with the attribute value pairs the element should have. Element writeAttribute takes care of that part. Instead of the annoying we can use Prototype s own Ele-ment update to set the text content of a new element. The last step is the same in all cases. We use Element down to hop from the table to its tbody and then we use Element insert to place our new element after all the other rows. CHAPTER 6 WORKING WITH THE DOM 135 The wrap Method Let s take a time-out from the example to talk about Element wrap. Sometimes you ll want to create a new element to act as a container for something that s already on the page. This is one mode of attack for browser bugs rendering issues for example can sometimes be defeated with a wrapper element. Prototype s Element wrap is shorthand for creating an element and specifying its contents all at once. Its arguments are identical to those of the Element constructor .

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.