js如何让下面这些多个同样的代码循环合并成一个function
$(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 ();});
}}); 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询