社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  Harmen  »  全部回复
回复总数  1
16 年前
回复了 Harmen 创建的主题 » 我使用的jquery太多了吗?我什么时候过这条线?

如果可以设置一个类属性而不是许多样式属性,则使用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;
}