jquery表样式vs css表样式为替代行 [英] jquery table styling vs css table styling for alternate rows

查看:138
本文介绍了jquery表样式vs css表样式为替代行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在服务器上生成奇数/偶数行的表上使用CSS,或者使用jQuery来对document.Ready()上的条纹进行样式,使用CSS更快,更好。

Is it faster/better to use CSS with classes on tables for odd/even rows generated on the server or to use jQuery to style stripes on document.Ready()?

我想开始使用jQuery来使我的标记更少杂乱,但我不确定性能,特别是对于更大(最多200行)表。

I'd like to start using jQuery to make my markup less cluttered but I'm not sure about the performance, particularly for larger (up to 200 rows) tables.

推荐答案

根据浏览器的不同,您可能没有选择。 jQuery将使用旧的浏览器,如IE7,没有第N个子选择器。

Depending on browser you may not have a choice. jQuery will work with older browsers like IE7 which don't have the Nth child selector.

理想情况下你应该使用css。

Ideally you should use css. The stylesheet is the best place for styles to go.

我会使用css和旧的浏览器的javascript备份。例如,如果你想斑马所有表尝试这样:

I would use css with a javascript backup for older browsers. If, for example, you want to zebra all tables try this:

tr:nth-child(2n+1), tr.odd { background:#911100; }
tr:nth-child(2n), tr.even { background:#222200; }

在jQuery中,如果浏览器是旧的,则添加.odd和.even类。

And in jQuery add the .odd and .even classes if the browser is old.

//You will need to check which browsers don't support n-th child. But I doubt IE will        for example...
if($.browser.msie && $.browser.version < 9) {
  $('tr:odd').addClass('odd');
  $('tr:even').addClass('even');
}

这篇关于jquery表样式vs css表样式为替代行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆