2016-09-27 31 views
1

我想突出顯示某一行,而我在特定的行上。我不得不使用onmouseover。如何將CSS類動態添加到鼠標懸停的表格行上

但這不是爲我而發生的。

這是cshtml中的表格定義。

       <table class="table"> 
            <thead> 
             <tr> 
              <th class="severityCheck"><input type="checkbox" value="" /></th> 
              <th>Customer Name</th> 
              <th>Site Name</th> 

              <th></th> 
             </tr> 
            </thead> 
            <tbody data-bind="foreach:CustomerList"> 
             <tr onclick="removepage();" onmouseover="changeRowColor(this)"> 

              <td> 
               <input class="checkbox" data-bind="attr: { Id: 'checkbox' + $data.Id },click:$parent.customerClick" type="checkbox"> 

              </td> 
              <td class="col-md-4"> 
               <span class="name" data-bind="text:customerName" /> 

              </td> 
              <td> 
               <span data-bind="text:siteName" /> 
              </td> 

             </tr> 
            </tbody> 
           </table> 

要突出鼠標懸停,我寫的changeRowColor爲:

function changeRowColor(row) { 
    row.addClass = 'active'; 

} 

但類沒有被反映出來。但是當我做

row.style.backgroundColor= 'red'; 

它的發生。

我在做什麼錯?

此外,我必須突出顯示當前行,只有當鼠標位於此之上而鼠標離開時不會突出顯示。

我該怎麼做?

+0

你試過這樣做:懸停? – Gabbax0r

+0

他們是你使用JS而不是CSS的原因嗎? – Shaggy

+0

這已經在stackoverflow上回答了上千次。我已經鏈接到一個,你會發現更多的搜索。 – Jamiec

回答

1

爲什麼不使用CSS

table tr:hover td{background-color:red;} 
+0

我必須使用JavaScript似乎。 CSS我不允許改變。 – StrugglingCoder

相關問題