這樣寫只能實現一行的背景變色和恢復原色
var change=document.getElementsByTagName("tr");
? ? change[0].onmouseover=function(){
? ? ? ? ?document.getElementsByTagName("tr")[0].style.backgroundColor="#f2f2f2";
? ? ? ? ? ?}
? ? change[1].onmouseover=function(){
? ? ? ? ?document.getElementsByTagName("tr")[1].style.backgroundColor="#f2f2f2";
? ? ? ? ? ?}
? ? change[2].onmouseover=function(){
? ? ? ? ?document.getElementsByTagName("tr")[2].style.backgroundColor="#f2f2f2";
? ? ? ? ? ?}
? ? change[0].onmouseout=function(){
? ? ? ? ?document.getElementsByTagName("tr")[0].style.backgroundColor="white";
? ?/* change[1].onmouseout=function(){
? ? ? ? ?document.getElementsByTagName("tr")[1].style.backgroundColor="white";*/
? ?/* change[2].onmouseout=function(){
? ? ? ? ?document.getElementsByTagName("tr")[2].style.backgroundColor="white";*/
如果把最后兩行任意一個解除注釋就無法實現題目要求的效果。這是為什么呢?
2016-03-25
已經知道用循環會方便很多。但是這個問題還是不太明白。