English 中文(简体)
J Query 2. 如何只选择目前的亲子,而不是父母
原标题:JQuery How to select only the current li and not parent
  • 时间:2010-08-18 10:07:28
  •  标签:
  • jquery

你们如何选择利用JQuery,而不是家长。

在我下面的样本中,当我凌驾于父母亲爱的利.上,世界就在父母和现在的亲子上展示。

我只想以目前的名义展示世界。

我如何这样做?

风格:

a.show-anyway
{
  display: block;
}
a.world
{
  display: none;
}
a.active
{
  display: block;
}

清单项目:

<ul class="currentlist">
<li><a href="#" class="show-anyway">hello</a><a href="#" class="world">world</a>
<li><a href="#" class="show-anyway">hello</a><a href="#" class="world">world</a>
 <ul>
   <li><a href="#" class="show-anyway">hello</a><a href="#" class="world">world</a></li>
   <li><a href="#" class="show-anyway">hello</a><a href="#" class="world">world</a></li>
 </ul>
</li>
<li><a href="#" class="show-anyway">hello</a><a href="#" class="world">world</a></li>
<li><a href="#" class="show-anyway">hello</a><a href="#" class="world">world</a>
 <ul>
   <li><a href="#" class="show-anyway">hello</a><a href="#" class="world">world</a></li>
   <li><a href="#" class="show-anyway">hello</a><a href="#" class="world">world</a></li>
 </ul>
</li>
<li><a href="#" class="show-anyway">hello</a><a href="#" class="world">world</a></li>

JQuery:

$(document).ready(function() {
  $( .currentlist li ).hover(function() {
    $(this).find( a ).addClass( active );
  }, function() {
    $(this).find( a ).removeClass( active );
  });
});
最佳回答

你们需要rawl倒父母,在进入/养育子女时增加/搬走该阶级。

$(function() {
  $( .currentlist li ).hover(function() {
    $(this).children( a ).addClass( active ).end()
           .parents().children( a ).removeClass( active );
  }, function() {
    $(this).children( a ).removeClass( active ).end()
           .parents().children( a ).addClass( active );
  });
});​

你们可以在这里让孩子们做一个尝试:,这个拖网把父母从他们的<条码>和>;a>儿童在进入时退学,并在离开时恢复审判,我认为这是你之后的。

问题回答

I think the issue is with eventbubbeling, I played around with it a bit at jsFiddle and have found some minor improvements. Try this for the jQuery part:

$(document).ready(function() {
  $( .currentlist li ).hover(function(evt) {
    $(this).children( a.world ).addClass( active );
      evt.stopPropagation()
  }, function(evt) {
    $(this).children( a.world ).removeClass( active );
  });
});​

这是解决办法的最恶劣之处,但也许会帮助你找到一种不祥的方式。

jsfiddle.net/s7TaT

这里的问题是,如果你 h着“孩子”的话,你仍然 h着自己的父母。 因此,你的职责完全是:

如果你只想在实际的“li”中增加活性成分,那么,你必须从所有“父母”中删除活性成分。

我建议不要在标签上添加这一类,而是在利方本身(实际上,它是一种活跃的、而不仅仅是其中的一个环节)

Try it here:





相关问题
getGridParam is not a function

The HTML: <a href="javascript:void(0)" id="m1">Get Selected id s</a> The Function: jQuery("#m1").click( function() { var s; s = jQuery("#list4").getGridParam( selarrrow )...

selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

jQuery cycle page with links

I am using the cycle plugin with pager functionality like this : $j( #homebox ) .cycle({ fx: fade , speed: fast , timeout: 9000, pager: #home-thumbs , ...

jquery ui dialog opens only once

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.

jConfirm with this existing code

I need help to use jConfirm with this existing code (php & Jquery & jAlert). function logout() { if (confirm("Do you really want to logout?")) window.location.href = "logout.php"; } ...

Wrap text after particular symbol with jQuery

What I m trying to do, is wrap text into div inside ll tag. It wouldn t be a problem, but I need to wrap text that appears particularly after "-" (minus) including "minus" itself. This is my html: &...

热门标签