English 中文(简体)
j Query: Highlight sub menu whenrollover main menu?
原标题:jQuery: Highlight sub menu when rollover main menu?
  • 时间:2012-01-14 19:16:26
  •  标签:
  • jquery

I have a nav & a secondary nav, both always on show.... but want I want to happen is, when you rollover "portfolio" in the main nav... I would like the "secondary nav" to light up e.g. apply a new class (with amore visible font colour)... how can this be done please?

(当你从“组合”开始时,字体的颜色又回到次地的正常状态)

<ul id="primarynav">
    <li><a href="">home</a></li>
    <li class="portfolio"><a href="">protfolio</a></li>
    <li><a href="">contact</a></li>
</ul>

<!-- Secondary nav -->

<ul id="secondarynav">
    <li><a href="">Websites</a></li>
    <li><a href="">Graphics</a></li>
    <li><a href="">Drawing</a></li>
</ul>
最佳回答

Us:

$(document).ready(function(){
    var $primarynav = $( #primarynav ),
        $secondarynav = $( #secondarynav );

    $primarynav.hover(function(){
        $secondarynav.addClass( highlight );
    }, function(){
        $secondarynav.removeClass( highlight );
    });
});
问题回答

首先,<li category=“portfolio”>,以便在你掌握以下要素后采用一种方法:

<li class="portfolio" onmouseover="highlightSecundarynav();">..</li>

之后,将撰写以下方法:highlightSecundarynav(,其中将这几类内容添加到小部分:

function highlightSecundarynav() {
  document.getElementById("secondarynav").setAttribute("class", "highlight");
}

之后,你可以添加一些特别安全局规则,以适用肤色或其他风格:

ul#secondarynav.highlight {
  color: #FF0000;
}

一旦修改后将项目组合重新排出,你必须做同样的工作,删除重点内容:

<li class="portfolio" onmouseover="highlightSecundarynav();" onmouseout="unhighlightSecundarynav();">..</li>

Javascript:

function unhighlightSecundarynav() {
  document.getElementById("secondarynav").setAttribute("class", "");
}




相关问题
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: &...

热门标签