在嵌套文件中,我需要在li hover上显示编辑和更新链接。我有jquery代码,它为我做。当我从上到下遍历时,Jquery工作正常但是当我从下到上遍历时,它不能按预期工作并显示父li的隐藏div。
我只想悬停李的跨度来展示。这是必需的。
<ul id="tree">
<li><span>Mobile </span> <span class="links" style="display: none;">Hey Hi, YOu
caught me!!!</span>
<ul class="subItem">
<li><span>GSM Mobiles </span> <span class="links" style="display: none;">Hey Hi,
YOu caught me!!!</span> </li>
<li><span>Smart Mobiles </span> <span class="links" style="display: none;">Hey
Hi, YOu caught me!!!</span>
<ul class="subItem">
<li><span>Android Mobiles </span> <span class="links" style="display: none;">Hey
Hi, YOu caught me!!!</span> </li>
<li><span>Sabian Mobiles </span> <span class="links" style="display: none;">Hey
Hi, YOu caught me!!!</span> </li>
</ul>
</li>
<li><span>Dual SIM Mobiles </span> <span class="links" style="display: none;">
Hey Hi, YOu caught me!!!</span> </li>
</ul>
</li>
<li><span>Watches </span> <span class="links" style="display: none;">Hey Hi, YOu
caught me!!!</span>
<ul class="subItem">
<li><span>Chronograph Watches </span> <span class="links" style="display: none;">
Hey Hi, YOu caught me!!!</span> </li>
<li><span>Water Resistance </span> <span class="links" style="display: none;">
Hey Hi, YOu caught me!!!</span> </li>
</ul>
</li>
</ul>
我的jQuery代码在这里:
$('ul li').hover(function () {
$("ul>li>span.links").hide();
$(this).find("span.links").first().show();
}, function () {
$("ul>li>span.links").hide();
$(this).find("span.links").first().hide();
});
以下是 jsFiddle 链接
答案 0 :(得分:1)
打印出$(这个)时我注意到了, 您正在选择内部和外部列表,在选择器中更具体:
$('#tree ul li').hover(function () {
$("ul>li>span.links").hide();
$(this).find("span.links").first().show();
}, function () {
$("ul>li>span.links").hide();
$(this).find("span.links").first().hide();
});