使用jQuery突出显示选定的ASP.NET DataGrid行(Using jQuery to Highlight Selected ASP.NET DataGrid Row)
通过在tr的click事件中使用toggleClass,可以很容易地突出显示所选的数据网格行。 但是如何在选择不同的行之后最好删除突出显示? 迭代所有行以不突出它们对于较大的数据网格而言可能变得昂贵。 我对最简单的解决方案以及最高效的解决方案感兴趣。
谢谢, 麦克风
It is easy to highlight a selected datagrid row, by for example using toggleClass in the tr's click event. But how best to later remove the highlight after a different row has been selected? Iterating over all the rows to unhighlight them could become expensive for larger datagrids. I'd be interested in the simplest solution, as well as the most performant.
Thanks, Mike
最满意答案
此方法将活动行存储到变量中。 变量开头的$只是我自己的jQuery对象的匈牙利表示法。
var $activeRow; $('#myGrid tr').click(function() { if ($activeRow) $activeRow.removeClass('active'); $activeRow = $(this).addClass('active'); });This method stores the active row into a variable. The $ at the start of the variable is just my own hungarian notation for jQuery objects.
var $activeRow; $('#myGrid tr').click(function() { if ($activeRow) $activeRow.removeClass('active'); $activeRow = $(this).addClass('active'); });更多推荐
发布评论