donglanying3855 2014-04-02 01:53
浏览 51
已采纳

更改所选菜单选项卡的颜色

How can I change in my code menu, for change the color of selected menu tab after click? this is my code:

php

<div class="meniu-item" onclick="$('#content').load('_core/home.php?rand='+Math.random()); window.location.hash = 'home';   ">Home</div>
<div class="meniu-item" onclick="$('#content').load('_core/after-login.php?what=help&rand='+Math.random()); window.location.hash = 'help';  ">Contact</div>

css

.meniu-item {
    display:block;
    float:left;
    background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #fdfdfd), color-stop(1, #f1f1f2) );
    background:-moz-linear-gradient( center top, #fdfdfd 5%, #f1f1f2 100% );
    filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#fdfdfd', endColorstr='#f1f1f2');
    background-color:#fdfdfd;
    border-right:1px solid #e0e0e0;
    color:#333333;
    font-family:Verdana;
    font-size:10px;
    font-weight:bold;
    padding:4px 0 0 0;
    text-decoration:none;
    text-shadow:1px 1px 0px #ffffff;
    cursor:pointer;
    height:25px;
    color:#4d4d4d;
    width: 97px;
    text-align:center;
    margin-top: 6px;
    line-height: 2;

}

Example:

http://www.codeproject.com/KB/webforms/MenuControlSelectedItem1/EndProduct1.JPG

  • 写回答

1条回答 默认 最新

  • doumi2106 2014-04-02 01:57
    关注

    Something like:

    <div data-uri="_core/home.php" class="meniu-item">Home</div>
    <div data-uri="_core/after-login.php" class="meniu-item">Contact</div>
    

    With the jQuery:

    $("div.meniu-item").on("click", function()
    {
        $('#content').load($(this).data("uri"));
        window.location.hash = $(this).text().toLowerCase();
    
        // Remove the class 'selected' from all navigation items first.
        $("div.meniu-item").removeClass("selected");
    
        // Then add it to the one we clicked.
        $(this).addClass("selected");
    
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条