簡體   English   中英

發出淡出選擇器的問題

[英]Issue fading out selector

我正在嘗試淡出單擊的ul元素。 這是東西,我有多個ul元素,它們在選擇時包含相同的類名。 為了解決這個問題,我正在逐步淘汰每個特定ulid ,以了解淡出哪個元素。 我的問題是,當嘗試淡出ul元素時。 即使它包含正確的id ,也不會發生任何事情。

這是我在做什么:

$(".start-dropdownClose").click(function(event){
       event.stopPropagation();
       $thisOne = $($(this).parent().parent().attr('id'));
       $($thisOne.selector).fadeOut();
});

當我提醒$thisOne.selector它會顯示所選ul元素的正確id 我只是不知道為什么它不會消失?

建議,想法?

不要使用其選擇器,只需使用element對象:

$(".start-dropdownClose").click(function(event){
   event.stopPropagation();
   $(this).parent().parent().fadeOut();
});

嘗試以下兩種方法:

$(".start-dropdownClose").click(function(event){
       event.stopPropagation();
       $thisOne = $(this).parent().parent();
       $thisOne.fadeOut();
});

要么

$(".start-dropdownClose").click(function(event){
       event.stopPropagation();
       $thisOne = $($(this).parent().parent().attr('id'));
       $("#"+$thisOne).fadeOut();
});

第一個$ thisOne是您要選擇並淡出的ul。 因此,只要淡出效果就可以。

在第二種方法中,$ thisOne是一個id字符串,因此要使用jQuery正確選擇它,正確的語法是$(“#idString”)

暫無
暫無

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

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