简体   繁体   English

如何使用jquery / javascript动态更改菜单样式?

[英]How to change the style of menus dynamically using jquery/javascript?

Hi i have a webpage where i have two types of menus 1)top menu (horizontal) 2)left menu (vertical) like this 嗨,我有一个网页,其中有两种菜单1)顶部菜单(水平)2)左侧菜单(垂直)

  Home  Portfolio  Help  Contact  styles

  <div id="menu1">
 <ul class="tabs">
<li><h4><a href="#">In the blog &raquo;</a></h4></li>
<li class="hasmore"><a href="#"><span>Recent</span></a>
    <ul class="dropdown">
        <li><a>Menu item 1</a></li>
        <li><a href="#" >Menu item 2</a></li>
        <li><a href="#">Menu item 3</a></li>
        <li><a href="#">Menu item 4</a></li>
        <li><a href="#">Menu item 5</a></li>
        <li class="last"><a href="#">Menu item 6</a></li>
    </ul>
</li>
<li class="hasmore"><a href="#"><span>Topics</span></a>
    <ul class="dropdown">
        <li><a href="#">Topic 1</a></li>
        <li><a href="#">Topic 2</a></li>
        <li><a href="#">Topic 3</a></li>
        <li class="last"><a href="#">Topic 4</a></li>
    </ul>
</li>   
<li><h4><a href="#">Elsewhere &raquo;</a></h4></li>
<li><a href="#"><span>About</span></a></li>
<li class="hasmore"><a href="#"><span>Networks</span></a>
    <ul class="dropdown">
        <li><a href="#">Twitter</a></li>
        <li><a href="#">posterous</a></li>
        <li><a href="#">SpeakerSite</a></li>
        <li><a href="#">LinkedIn</a></li>
        <li class="last"><a href="#">See more&hellip;</a></li>
    </ul>
</li>
<li><a href="#"><span>Bookmarks</span></a></li>

in the same way i have vertical which has a tab called styles,in both the styles tab i have 以同样的方式,我有垂直的,有一个称为样式的标签,在两个样式标签中,

    styles
    style-1
    style-2
    style-3
    style-3

Now my work is to when ever i want to change the style of menus dynamically i will go to style tab select the style and the style of the menus should be changed.... 现在我的工作是,当我想动态更改菜单样式时,我将转到样式选项卡,选择样式,然后更改菜单样式。

i dont know where to start ..please can any one help me with this or provide with example code will be gratefull to them 我不知道从哪里开始..请任何人可以帮我这个忙,或者提供示例代码,他们将不胜感激

Create two classes in stylesheet, one if the menu is vertical and one if the menu is horizontal. 在样式表中创建两个类,如果菜单是垂直的,则创建一个类,如果菜单是水平的,则创建一个类。 On clicking on an option in styles tab change the css class of menu div using jquery. 在样式选项卡中单击选项后,使用jquery更改菜单div的css类。

Check This 检查这个

use jQuery selectors for this purpose 为此使用jQuery选择器

like onmouseover event you can execute 像onmouseover事件,您可以执行

function f()
{
    $('#ms').removeCss("mass");
    $('#ms').addCss("mass2");    
}

your code could be 您的代码可能是

<li id="ms" class="mass" onmouseover="f();"><a href="#"><span>Networks</span></a>
    <ul class="dropdown">
        <li><a href="#">Twitter</a></li>
        <li><a href="#">posterous</a></li>
        <li><a href="#">SpeakerSite</a></li>
        <li><a href="#">LinkedIn</a></li>
        <li class="last"><a href="#">See more&hellip;</a></li>
    </ul>
</li>

IIRC, someone did this for you on the SO javascript chat already. IIRC,已经有人在SO javascript聊天中为您完成了此操作。

Here is the link: http://jsfiddle.net/NUaA5/ 这是链接: http : //jsfiddle.net/NUaA5/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM