[英]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.