如果可以设置一个类属性而不是许多样式属性,则使用jquery的次数太多。例如:
/** Select 400 rows and change the background colour **/
$('#table tr').css('backgroundColor', 'blue');
而不是:
/** jQuery **/
$('#table').addClass('blueRows');
/** CSS **/
#table tr.blueRows {
background-color: blue;
}
为了避免jquery样式,您还可以为主体设置一个类,以便在启用了javascript的浏览器中更容易使用CSS进行样式设置:
/** jQuery **/
$(document).addClass('JS-enabled');
/** CSS **/
body #table tr{
background: #FFF;
}
body.JS-enabled #table tr {
background: blue;
}