2016-02-29 26 views
0

我希望能夠一次選擇一個盒子,並在盤旋時顯示一個彈出框,但它們具有相同的div類名,每當我懸停時,所有其他盒子彈出以及。在動態div上一次選擇一個div

<div class="parent"> //select one at a time when hovered here 
<a href="#" class="show">show content1</a> 
</div> 

<div class="parent"> 
<a href="#" class="show">show content2</a> 
</div> 

<div class="hidden">show this text one at a time when hovered</div> 

我試過。對jQuery的使用,因爲它不綁定到一個單一的元素,.toggle,但它不工作,它會顯示所有在同一時間。

http://jsfiddle.net/2XG9j/9/

+0

我不明白你的要求。你一次一個意思是什麼?或全部在同一時間。起初我以爲這是一條消息,但由於它的信息相同,我沒有得到你需要的東西 – jstuartmilne

+0

每個隱藏的消息都會有所不同,因爲它們將被動態創建,但在本例中,我只是將它作爲一個靜態消息 – evelyn

+0

Check我的答案。那是你要的嗎? – jstuartmilne

回答

0

一個會提示你的要求? https://jsfiddle.net/y3llowjack3t/p9rwop58/

<div class="parent"> 
<a href="#" title="show1 this text one at a time when hovered">show content1</a> 
</div> 

<div class="parent"> 
<a href="#" title="show2 this text one at a time when hovered">show content2</a> 
</div> 

<div style="display: none;">show this text one at a time when hovered</div> 

$(".parent").tooltip(); 
+0

我想添加很多信息,所以我不想使用這個 – evelyn

0

嘗試增加該事件的每個元素:

$('.show').each(function(i,e){ 
    $(e).click(function(){ 
     $('.hidden').fadeIn(); 
    }); 
}); 
0

如果我正確理解。試試這個

http://jsfiddle.net/anbby8se/

$(document).on({ 
    mouseenter: function(e){ 
     $('.hidden').text($(e.target).text()); 
     $(".hidden").css({ 
       'display' : 'block' 
      }); 

    }, 
    mouseleave: function(){ 
     $(".hidden").css({ 
       'display' : 'none' 
      }); 
    } 
}, '.parent'); 

請注意,我只是抓住了錨的內容。因爲我不知道你想表現什麼。