簡體   English   中英

如何取消設置 jquery 所做的更改?

[英]How can i unset the changes made by jquery?

我正在根據第一個字符過濾數據,但是當用戶單擊全部時,我想顯示所有數據,但是一旦根據字符過濾了數據,我就無法將其重置為全部。

我想允許用戶根據字母用戶 select 過濾數據,當用戶單擊所有用戶應該能夠再次看到所有項目。

我的代碼:

$('.myFilters li').on("click", function() {
    if($(this).text() == "all"){
        $(this).show();
        return ;
    }
    var letter = $(this).text()[0];

    $('#mycatouter div').each(function() {
    letter=letter.toUpperCase();
    if ($(this).text()[0] == letter) {
      $(this).show();
    } else {
      $(this).hide();
    }
    });
});

問題在於this關鍵字的使用:

$('.myFilters li').on("click", function() {
    if($(this).text() == "all"){
        $('#mycatouter div').show();
        return;
    }
    var letter = $(this).text()[0];

    $('#mycatouter div').each(function() {
      letter = letter.toUpperCase();
      if ($(this).text()[0] == letter) {
        $(this).show();
      } else {
        $(this).hide();
      }
    });
});

在您的第一個 if 中, this指的是事件目標,而在each循環中,它指的是循環中的當前元素。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM