tailieunhanh - The javascript anthology 101 essential tips tricks hacks - phần 9

Việc đầu tiên cho vòng lặp xảy ra sau khi tất cả các biến cấu trúc đã được xác định thiết lập trạng thái tương ứng cho mỗi bảng nhóm tế bào khi một trong số họ được nhấp. | Sorting Tables by Column newTbody targetTbody stopDefaultAction event return false The first for loop that occurs after all the structural variables have been defined sets the respective states for each of the table heading cells when one of them is clicked. Not only are classes maintained to identify the heading cell on which the table is currently sorted but a special sortOrder property is maintained on each cell to determine the order in which that column is sorted. Initially a column will be sorted in descending order but if a heading cell is clicked twice consecutively the sort order will be changed to reflect an ascending sequence. Each heading cell remembers the sort order state it exhibited most recently and the column is returned to that state when its heading cell is re-selected. The title of the hyperlink for a clicked heading cell is also rewritten depending upon the current sort order and what the sort order would be if the user clicked on it again. The second for loop sorts each of the rows that s contained in the body of the table. A copy of the original tbody is created to store the reordered table rows and initially this copy is empty. As each row in the original tbody is scanned the contents of the table cell in the column on which we re sorting is compared with the rows already in the copy. In order to find the contents of the table cell we use the function getInternalText File excerpt function getlnternalText target var elementChildren var internalText for var i 0 i i if elementChildren i .nodeType 3 if A s .test elementChildren i .nodeValue internalText elementChildren i .nodeValue Order the print version of this book to get all 588 pages 263 Chapter 13 Basic Dynamic HTML else internalText getInternalText elementChildren i return internalText getInternalText extracts all of the text inside an element including all of its descendant elements by .

TỪ KHÓA LIÊN QUAN