我正在利用每种方法来启动与其中存在的<td>
相关的工具提示。在IE,Chrome,Safari中,一切都运行良好,但Firefox完全缺少每种方法,并且只启动DOM中的最后一个工具提示。
是什么给出了?
HTML:
<div class="stage">
<div class="dealFinder">
<h2 class="title">Deal Finder in Your Area</h2>
<table cellpadding="5">
<tr>
<td class="text">
<p class="makeModel"><a href="#">2012 Land Rover Range Rover Evoque</a><br>in Oak Lawn</p>
<a class="youSave" href="#" onclick="return false"> You Save at Least $14,810</a>
<div class="tooltip">
<div class="inner">
<b>2012 Land Rover Range Rover Evoque</b>
<span>Your Price $19,330</span>
<p>The National Average is <b>$21,500</b></p>
</div>
</div>
</td>
<td class="pic">
<a href="#"><img src="http://placehold.it/113x75" /></a>
</td>
</tr>
<tr>
<td class="text">
<p class="makeModel"><a href="#">2012 Land Rover Range Rover Evoque</a><br>in Oak Lawn</p>
<a class="youSave" href="#" onclick="return false"> You Save at Least $14,810</a>
<div class="tooltip">
<div class="inner">
<b>2012 Land Rover Range Rover Evoque</b>
<span><small>Your Price</small> $19,330</span>
<p>The National Average is <b>$21,500</b></p>
</div>
</div>
</td>
<td class="pic">
<a href="#"><img src="http://placehold.it/113x75" /></a>
</td>
</tr>
</table>
</div><!-- .dealFinder -->
</div>
jQuery的:
$(document).ready(function() {
// Tooltip
$('.tooltip').hide();
$('.text').each(function(e) {
var self = this;
var tooltip = $(self).find('.tooltip');
var youSave = $(self).find('.youSave');
$(youSave).mouseenter(function(e) {
$(self).find(tooltip).fadeIn("slow");
});
$(youSave).mouseleave(function(e) {
$(self).find(tooltip).fadeOut("fast");
});
});
});
答案 0 :(得分:2)
几乎不需要每个函数迭代元素只是为了将它们绑定到事件处理程序:
$(document).ready(function() {
$('.tooltip').hide();
$('.youSave', '.text').on('mouseenter mouseleave', function() {
$(this).next('.tooltip').fadeToggle('slow');
});
});
其余的只是将工具提示放在按钮顶部的放置问题,并且应该用一点CSS来修复。
答案 1 :(得分:1)
开始它写得很奇怪。试试:
$('.text .youSave').mouseenter(function(){
var item = $(this);
var tooltip = $('.tooltip', item.parent()).fadeIn();
});
//the same way for mouseleave
并提供工具提示display:none默认为什么用js更改它?
我看到了问题。工具提示fadein你的鼠标和火灾事件mouseleave。易于修复。工具提示必须是.youSave元素子:
<a class="youSave" href="#" onclick="return false"><span> You Save at Least $14,810<span>
<div class="tooltip">
<div class="inner">
<b>2012 Land Rover Range Rover Evoque</b>
<span>Your Price $19,330</span>
<p>The Web2Carz National Average is <b>$21,500</b></p>
</div>
</a>
然后JS:
$('.text .youSave').mouseenter(function(){
var item = $(this);
var tooltip = $('.tooltip', item).fadeIn();
});