2011-04-03 24 views
1

當我的皮膚應用到我的gridview時,我的jQuery腳本不起作用。一旦我加入皮膚,我就再也找不到了。我認爲這與tr構建方式有關。皮之不存,該行是乾淨使用jQuery皮膚找不到gridview行

<tr>data</tr>. 

但與皮膚現在該行

<tr style=....>data</tr> 

這裏是我的jQuery的,做的時候,我沒有應用到GV皮膚工作。

$(document).ready(function() { 
     $('tr').mouseover(function() { 
      $(this).toggleClass('highlightrow'); 
       }).mouseout(function() { 
        $(this).removeClass('highlightrow'); 
       }) 
    }); 

回答

1

行被發現就好了,問題是,他們已經「硬編碼」,在其style所以在class背景色背景色沒有效果。

解決此問題的一個方法是存儲以前的顏色,然後直接將背景色設置爲mouseover,並在鼠標移出事件中恢復以前的顏色(以保留皮膚)。

代碼是這樣:

$(document).ready(function() { 
    $('tr').mouseover(function() { 
     $(this).data("prev_color", $(this).css("background-color")); 
     $(this).toggleClass('highlightrow').css("background-color", "yellow"); 
    }).mouseout(function() { 
     $(this).removeClass('highlightrow').css("background-color", $(this).data("prev_color")); 
    }); 
}); 

現場測試案例:http://jsfiddle.net/yahavbr/awEaP/1/

+0

謝謝!很棒。我剛剛添加了$('tr:not(:first)')。mouseover(function(){爲了避免突出顯示標題 – IMAbev 2011-04-03 15:06:32

+0

@IMAbev歡呼,很高興我能幫忙,並感謝分享這些有用的信息!:) – 2011-04-03 15:17:46

+0

fyi I在具有.gridlink類的頁面上有多個gridviews。 tr:not(:first)隻影響第一個gridview。我改爲tr:not(:firstchild),它只突出顯示所有gv的行 - 不是頭文件 – IMAbev 2011-04-03 20:06:26

1

我敢打賭,這是由於比你css具有較高的優先級style。您的highlightrow如何定義?例如,如果您在此處指定background-color並且它也位於trstyle中,則會被忽略。

也許添加!important條款可以幫助:

.highlightrow 
{ 
    background-color: Red !important; 
} 
+0

,做的工作。唯一的缺點是它也突出表頭。從來不知道!重要條款。我想知道這是瀏覽器支持? – IMAbev 2011-04-03 15:01:54

+1

@IMA這裏是解釋:http://stackoverflow.com/questions/189621/when-does-csss-important-declaration-not-work – 2011-04-03 15:16:30

+1

@IMAbev:關於!重要的支持:http://stackoverflow.com/questions/1330184/what-browsers-support-important – 2011-04-03 15:16:45