jquery <li>标签 隔若干行 加空白或者加虚线


$(function () {


$('ul li').addClass(function (i) { return i % 6 == 5 ? "ab" : ""; }); // 隔6行 加空白。或者加虚线

$('.imglist li').after(function (i) {
var css = "";
if (i % 3 == 2) {
css = "<div class='dashed clear' ></div>";
}
return css;
}); //图片列表photo.html 隔3行 虚线



});

 

i 是 <li>的索引号,从0开始

图片隔三行加虚线,最后一行去掉虚线,还可以这样

    //方法一:
    jQuery(document).ready(function () {
        var NewUL = jQuery(".photo_list ul li");
        for (var i = 0; i < NewUL.length; i++) {
            if ((i + 1) % 3 == 0) {
                NewUL.eq(i).after("<li class="photo_space"></li>");
            }
        }
        $(".photo_list li:last").css("border-bottom", "none");
    })
    
.ab

{

  height:80px;

}
.dashed{border-bottom:1px dashed #b9c3c7;padding-bottom:10px;margin-bottom:10px}
.clear{clear:both}
.imglist ul li {text-align:center;line-height:25px;float:left}

 

原文地址:https://www.cnblogs.com/qigege/p/4766242.html