我有这个脚本:
$(function(){
$(".submenu li:even").addClass("oddrow");
});
它工作得很好 - 但它继续在所有子菜单中进行条纹...
我如何包含它,以便它在每个子菜单的开头再次开始
最佳答案
您可以使用 context限制选择(我想您有各种 <ul>
包含您的 <li>
),以便您迭代 <ul>
然后仅选择偶数 <li>
其中<ul>
$(function(){
$(".submenu ul").each(function(){
//provide a context so that it select only `<li>` that are
//descendant of that `<ul>` `this` is the current `<ul>`
$("li:even", this).addClass("oddrow");
});
});
关于Jquery 条纹行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9192044/