[英]$(this).hide() hides containers it shouldn't
我有這段代碼可以過濾結果列表,並隱藏不匹配的div。 我正在為PhoneGap iOS應用程序編寫此代碼。 它在Android上運行良好,但是在iOS上由於某種原因,它在輸入了幾個字符后不僅會顯示結果,還會隱藏整個搜索字段。
知道為什么嗎? 我已經將其簡化為幾乎僅HTML代碼和jQuery,並且仍在繼續。 我試圖注釋掉$(this).hide();
部分,它停止隱藏搜索字段,因此我以某種方式認為是罪魁禍首,但我不知道為什么或如何解決此問題。 連續10個小時都在這里。 有任何想法嗎? 也許我可以將結果定位為其他方式?
$('#box_search').keyup(function() {
var valThis = $(this).val().toLowerCase();
if (valThis == "") {
$('#listing-results > .listing_container').show();
} else {
$('#listing-results > .listing_container').each(function() {
var text = ($(this).find('.listing_results_text_name').text() + $(this).find('.listing_results_text_name').data("alt")).toLowerCase();
if (text.indexOf(valThis) >= 0) {
$(this).show();
} else {
$(this).hide();
}
});
};
});
顯然我看不到html,但有時它有助於清理代碼並只是稍微改變邏輯
var box_search = function(e){
var myIndex = $(this).val();
val = (!myIndex || myIndex==='')?false:myIndex;
if(!myIndex){
$('#listing-results > .listing_container').show();
return;
}
//
$('#listing-results > .listing_container').each(function() {
var text = $(this).find('.listing_results_text_name').text() +
$(this).find('.listing_results_text_name').data("alt")
text = (!text || text==='')?false:text;
text = text.toLowerCase();
if(text.indexOf(myIndex.toLowerCase()) >= 0){
$(this).show();
return;
}
$(this).hide();
});
} //end of function
$('.box_search').keyup(box_search);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.