使用jQuery突出显示选定的ASP.NET DataGrid行(Using jQuery to Highlight Selected ASP.NET DataGrid Row)

系统教程 行业动态 更新时间:2024-06-14 17:03:54
使用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'); });

更多推荐

本文发布于:2023-04-24 14:12:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/36fcd2b17321632519ef506af4b8bcb5.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:NET   ASP   jQuery   DataGrid   Row

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!