2012-08-08 79 views
0

我想文本將鼠標懸停在「我」以及它與「你」彈出。的onmouseover不正確

<div class="relative"> 
<p onmouseover="document.getElementById('toolTipDiv').className='activeToolTip'" 
onmouseout="document.getElementById('toolTipDiv').className='idleToolTip'">Me<p/> 
<div id="toolTipDiv" class="idleToolTip">You.</div> 
</div> 
+0

YoungSam似乎忘了回答你的問題。請仔細查看我的解決方案。這可能對我有幫助。 – Codegiant 2013-01-08 06:12:00

回答

0

我會推薦使用jQuery!

您tooltipDiv應該有display: none爲CSS屬性,然後使用:

<p onmouseover="$('#toolTipDiv').show();" 
onmouseout="$('#toolTipDiv').hide();">Me<p/> 

如果您tooltipDiv顯示在「我」的文字,那麼你有一個問題,因爲onmouseout事件被觸發。不知道你的工具提示出現在哪裏!

0

HTML

<p class="me">Me</p> 
<div id="activeToolTip">You</div> 

jQuery的

$('.me').hover(function() { 
    $('#toolTipDiv').removeClass('idleToolTip').addClass('activeToolTip'); 
}, function(){ 
    $('#toolTipDiv').removeClass('activeToolTip').addClass('idleToolTip'); 
}); 

OR

僅供展示你可以做:

$('.me').hover(function() { 
    $('#toolTipDiv').toggle() 
}); 
+0

是代碼運作? – Codegiant 2012-08-08 10:26:16