tailieunhanh - Simply JavaScript phần 9

Có một hàng trong đó chúng tôi không muốn dễ bị hàng phân chia bên trong thead. Để tránh ảnh hưởng đến hàng này thông qua các shenanigans phân chia hàng của chúng tôi, chúng ta cần để có được chỉ các hàng được bên trong tbody một. | Document Access 95 tr tbody table There s one row in there that we don t want to be susceptible to striping the row inside the thead. To avoid affecting this row through our row striping shenanigans we need to get only the rows that are inside a tbody. This means we must add a step to our code we need to get all of the tbody elements in the table HTML allows more than one to exist then get all the rows inside each tbody. This process will actually require two for loops one to step through each of the table elements in the document and another inside that to step through each of the tbody elements but that s fine it just means more work for the computer. Since the variable name i is used for the counter in the outer for loop we ll name the counter variable in our inner for loop j excerpt for var i 0 i i var tbodys tables i .getElementsByTagName tbody for var j 0 j j var rows tbodys j .getElementsByTagName tr The results for both uses of getElementsByTagName in the code above will be limited to the current table because we re using it as a method of a particular element not the entire document. The variable rows now contains a collection of all the tr elements that exist inside a tbody element of the current table. Order the print version of this book to get all 400 pages 96 Simply JavaScript Adding the Class alt to Every Second Row For every is equivalent to for each here so we know that we re going to use yet another for loop. It will be a slightly different for loop though because we only want to modify every second row. To do this we ll start the counter on the second index of the collection and increment it by two not one excerpt for var i 0 i i var tbodys tables i .getElementsByTagName tbody for var j 0 j j var rows tbodys j .getElementsByTagName tr for var k 1 k k 2 rows k alt We re already using the variables i and j as the counters for the .

TỪ KHÓA LIÊN QUAN
crossorigin="anonymous">
Đã 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.