亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

嵌套在each()中的函數,該函數應用于所有元素,而不是單個元素

嵌套在each()中的函數,該函數應用于所有元素,而不是單個元素

慕容3067478 2021-05-14 15:08:01
我有一個用于將分頁應用于一系列類的jquery腳本。大多數情況下,一切正常,除了我有一個嵌套函數(showPage),該函數僅應應用于當前類,而應在所有類中使用元素,并將操作應用于最后一項。已經嘗試過切換到for循環而不是切換到each循環,但是提供了相似的功能,但存在相同的問題。$(document).ready(function() {  var lists = document.getElementsByClassName('content_display');  listSize = 5;  var fourWide = window.matchMedia("(max-width: 800px)");  var threeWide = window.matchMedia("(max-width: 600px)")  if (fourWide.matches) {    // Screen is less than 800px    listSize = 4;  }  if (fourWide.matches) {    // Screen is less than 600px    listSize = 3;  }  $(lists).each(function() {    var contentCount = $(this).find('ul li').length    var pageCount = contentCount / listSize;    if (contentCount < listSize)      $(this).find(".content_more").hide()    var $e = $(this)    var $f = $(this).find('.content_item')    for (var i = 0; i < pageCount; i++) {      $(this).find(".pagination").append('<a href="#">' + (i + 1) + '</a> ');    }    $(this).find(".pagination a").first().addClass("active")    showPage = function(page) {      $f.hide();      $f.each(function(n) {        if (n >= listSize * (page - 1) && n < listSize * page)          $(this).show();      });    }    showPage(1);    $(this).find(".pagination a").click(function() {      $e.find(".pagination a").removeClass("active");      $(this).addClass("active");      showPage(parseInt($(this).text()))    });  });})
查看完整描述

1 回答

  • 1 回答
  • 0 關注
  • 174 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號