本文实例分析了jquery实现隔行变色的方法。分享给大家供大家参考,具体如下:
原生js:
var tab = document.getElementByTagName('table')[0]; var tr = tab.getElementByTagName('tr'); for(var i=0;i<tr.length;i++){ if(i%2==0){ tr[i].style.background="orange"; }else{ tr[i].style.background="#abcdef"; } }
jquery dom选择器:
$('table tr:odd').css('background','orange'); $('table tr:even').css('background','#abcdef');
jquery 方法选择器:
$('table tr').filter(':odd').css('background','orange').end().filter(':even').css('background','#abcdef');
有很多的方法 ,多学一点知识,少写一行代码。
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号