jquery如何将下面这些多个同样不同值的代码循环合并成一个代码,下面一个还有10多个,不一一贴出来了。 10
$(function(){varlen=$(".set-listdiv:eq(0)li").length;varle=len-40;varlf=len-39;varlc=...
$(function () {
var len = $(".set-list div:eq(0) li").length;
var le =len-40;
var lf =len-39;
var lc =len-6;
if (len > 40) {
$(".set-list div:eq(0) li:gt(33):lt("+le+")").hide();
$(".set-list div:eq(0) li:gt("+lc+")").show();
$(".set-list div:eq(0) li").filter(":nth-child(34)").after("<li class='la'><a>......</a></li>");
$(".set-list div:eq(0) li").filter(":last").after("<li class='lb' style='display:none'><a>收缩</a></li>");
$(".set-list div:eq(0) .la").click(function(){$(".set-list div:eq(0) li").show();$(".set-list div:eq(0) li").filter(":nth-child(35)").hide ();});
$(".set-list div:eq(0) .lb").click(function(){$(".set-list div:eq(0) li:gt(34):lt("+lf+")").hide();$(".set-list div:eq(0) li").filter(":nth-child(35)").show();$(".set-list div:eq(0) li").filter(":last").hide ();});
}});
$(function () {
var len = $(".set-list div:eq(1) li").length;
var le =len-40;
var lf =len-39;
var lc =len-6;
if (len > 40) {
$(".set-list div:eq(1) li:gt(33):lt("+le+")").hide();
$(".set-list div:eq(1) li:gt("+lc+")").show();
$(".set-list div:eq(1) li").filter(":nth-child(34)").after("<li class='la'><a>......</a></li>");
$(".set-list div:eq(1) li").filter(":last").after("<li class='lb' style='display:none'><a>收缩</a></li>");
$(".set-list div:eq(1) .la").click(function(){$(".set-list div:eq(1) li").show();$(".set-list div:eq(1) li").filter(":nth-child(35)").hide ();});
$(".set-list div:eq(1) .lb").click(function(){$(".set-list div:eq(1) li:gt(34):lt("+lf+")").hide();$(".set-list div:eq(1) li").filter(":nth-child(35)").show();$(".set-list div:eq(1) li").filter(":last").hide ();});
}});
$(function () {
var len = $(".set-list div:eq(2) li").length;
var le =len-40;
var lf =len-39;
var lc =len-6;
if (len > 40) {
$(".set-list div:eq(2) li:gt(33):lt("+le+")").hide();
$(".set-list div:eq(2) li:gt("+lc+")").show();
$(".set-list div:eq(2) li").filter(":nth-child(34)").after("<li class='la'><a>......</a></li>");
$(".set-list div:eq(2) li").filter(":last").after("<li class='lb' style='display:none'><a>收缩</a></li>");
$(".set-list div:eq(2) .la").click(function(){$(".set-list div:eq(2) li").show();$(".set-list div:eq(2) li").filter(":nth-child(35)").hide ();});
$(".set-list div:eq(2) .lb").click(function(){$(".set-list div:eq(2) li:gt(34):lt("+lf+")").hide();$(".set-list div:eq(2) li").filter(":nth-child(35)").show();$(".set-list div:eq(2) li").filter(":last").hide ();});
}}); 展开
var len = $(".set-list div:eq(0) li").length;
var le =len-40;
var lf =len-39;
var lc =len-6;
if (len > 40) {
$(".set-list div:eq(0) li:gt(33):lt("+le+")").hide();
$(".set-list div:eq(0) li:gt("+lc+")").show();
$(".set-list div:eq(0) li").filter(":nth-child(34)").after("<li class='la'><a>......</a></li>");
$(".set-list div:eq(0) li").filter(":last").after("<li class='lb' style='display:none'><a>收缩</a></li>");
$(".set-list div:eq(0) .la").click(function(){$(".set-list div:eq(0) li").show();$(".set-list div:eq(0) li").filter(":nth-child(35)").hide ();});
$(".set-list div:eq(0) .lb").click(function(){$(".set-list div:eq(0) li:gt(34):lt("+lf+")").hide();$(".set-list div:eq(0) li").filter(":nth-child(35)").show();$(".set-list div:eq(0) li").filter(":last").hide ();});
}});
$(function () {
var len = $(".set-list div:eq(1) li").length;
var le =len-40;
var lf =len-39;
var lc =len-6;
if (len > 40) {
$(".set-list div:eq(1) li:gt(33):lt("+le+")").hide();
$(".set-list div:eq(1) li:gt("+lc+")").show();
$(".set-list div:eq(1) li").filter(":nth-child(34)").after("<li class='la'><a>......</a></li>");
$(".set-list div:eq(1) li").filter(":last").after("<li class='lb' style='display:none'><a>收缩</a></li>");
$(".set-list div:eq(1) .la").click(function(){$(".set-list div:eq(1) li").show();$(".set-list div:eq(1) li").filter(":nth-child(35)").hide ();});
$(".set-list div:eq(1) .lb").click(function(){$(".set-list div:eq(1) li:gt(34):lt("+lf+")").hide();$(".set-list div:eq(1) li").filter(":nth-child(35)").show();$(".set-list div:eq(1) li").filter(":last").hide ();});
}});
$(function () {
var len = $(".set-list div:eq(2) li").length;
var le =len-40;
var lf =len-39;
var lc =len-6;
if (len > 40) {
$(".set-list div:eq(2) li:gt(33):lt("+le+")").hide();
$(".set-list div:eq(2) li:gt("+lc+")").show();
$(".set-list div:eq(2) li").filter(":nth-child(34)").after("<li class='la'><a>......</a></li>");
$(".set-list div:eq(2) li").filter(":last").after("<li class='lb' style='display:none'><a>收缩</a></li>");
$(".set-list div:eq(2) .la").click(function(){$(".set-list div:eq(2) li").show();$(".set-list div:eq(2) li").filter(":nth-child(35)").hide ();});
$(".set-list div:eq(2) .lb").click(function(){$(".set-list div:eq(2) li:gt(34):lt("+lf+")").hide();$(".set-list div:eq(2) li").filter(":nth-child(35)").show();$(".set-list div:eq(2) li").filter(":last").hide ();});
}}); 展开
2017-11-13
展开全部
$(function() {
//10个div
for (var i = 0; i < 10; i++) {
var div = $(".set-list div:eq(" + i + ")");
var lis = div.find("li");
var len = lis.length;
var le = len - 40;
var lf = len - 39;
var lc = len - 6;
if (len > 40) {
div.find("li:gt(33):lt(" + le + ")").hide();
div.find("li:gt(" + lc + ")").show();
lis.filter(":nth-child(34)").after("<li class='la'><a>......</a></li>");
lis.filter(":last").after("<li class='lb' style='display:none'><a>收缩</a></li>");
div.find(".la").click(function() {
lis.show();
lis.filter(":nth-child(35)").hide();
});
div.find(".lb").click(function() {
div.find("li:gt(34):lt(" + lf + ")").hide();
lis.filter(":nth-child(35)").show();
lis.filter(":last").hide();
});
}
}
});
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询