📜  显示更多实现 jquery - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:04:16.433000             🧑  作者: Mango

代码示例1
var $li = $('ul li');
var $shPets = $('.shPets');

$shPets.each(function() {
  var petType = $(this).data('pet');
  $('ul li[data-pet=' + petType + ']')
    .not('.shPets') //not shPets
    .not(':first') //everything except first
    .hide();
});

$('.shPets').click(function() {
  var petType = $(this).data('pet');
  if ($(this).text() == 'Show More..') {
    $(this).text('Hide');
    $('ul li[data-pet=' + petType + ']').show();
  } else {
    $(this).text('Show More..');
    $('ul li[data-pet=' + petType + ']')
      .not('.shPets') //not shPets
      .not(':first') //everything except first
      .hide();
  }
});