這段代碼沒太理解,求指教!
?function?Highlight(){????? ?var?tbody?=?document.getElementById('table').lastChild; ?//table節點的最后一個子節點不是最后一個tr節點嘛?怎么成數組了? ?trs?=?tbody.getElementsByTagName('tr');??? ?for(var?i?=1;i<trs.length;i++){???? ?trs[i].onmouseover?=?function(){ ?this.style.backgroundColor?="#f2f2f2"; }? ?trs[i].onmouseout?=?function(){ ?this.style.backgroundColor?="#fff"; }? ?}
table節點的最后一個子節點不是最后一個tr節點嘛?怎么成數組了?
table節點的最后一個子節點不是最后的tr節點嘛?怎么成數組了?for循環里面的語句是什么意思呢?
2018-07-23
table節點的最后一個子節點應該是tbody,這個表格省略了thead和tbody,所以不好理解。
2018-07-04
var
?tbody?=?document.getElementById(
'table'
)獲取的是所有的子節點,所有的節點構成數組,你要得到最后一個節點相當于取數組的最后一個元素,數組a = [1,2,3,4,5,6],你要得到6這個元素就要這樣寫 a[5].for循環循環tr(行元素),你現在的trs里面只有一個tr