yuzhenying 2018-03-30 17:05:15 1170次浏览 0条评论 1 0 0

问题: 点击头部导航栏,左侧菜单栏不能同时加深颜色;点击左侧菜单栏,清空头部导航栏加深颜色效果。 效果图: bootstrap_header.jpg 当时情景: 布局:herder.php,nav.php同时include_once()在index.php文件中; 代码: header.php如下:

            <ul class="nav navbar-nav">
                <li >
                    <a href="/redirect/index.php" role="tab">Redirect(3方)</a>
                </li>
                <li >
                    <a href="/direct/index.php" role="tab" id="direct">Direct(2方)</a>
                </li>
                <li >
                    <a href= "/reconciliation/index.php" role="tab">对账API</a>
                </li>
                <li >
                    <a href= "/successOrder/index.php" role="tab">获取成功订单API</a>
                </li>
                <li >
                    <a href= "/refund/index.php" role="tab">退款API</a>
                </li>
                <li >
                    <a href= "/preAuthorization/index.php" role="tab">预授权API</a>
                </li>
                <li >
                    <a href= "/logistics/index.php" role="tab">物流信息上传API</a>
                </li>
                <li >
                    <a href= "/other/index.php" role="tab">其他业务状态推送</a>
                </li>
                <li >
                    <a href= "/excursus/index.php" role="tab">附录</a>
                </li>
                <li >
                    <a href= "/sha/index.php">sha256加密方式</a>
                </li>
            </ul>

nav.php如下:
        <li class="nav-header">
            介绍
        </li>
        <li>
            <a href="/redirect/index.php"><i class="icon-file"></i> 文档介绍</a>
        </li>
        <li >
            <a href="/redirect/version.php"><i class="icon-file"></i> 版本说明</a>
        </li>
        <li class="nav-header">
            交易
        </li>
        <li >
            <a href="/redirect/business.php"><i class="icon-file"></i> 业务流程时序图</a>
        </li>
        <li >
            <a href="/redirect/submit.php"><i class="icon-file"></i> 提交地址</a>
        </li>
        <li >
            <a href="/redirect/requestParaments.php"><i class="icon-file"></i> 请求参数</a>
        </li>
        <li >
            <a href="/redirect/example.php"><i class="icon-file"></i> 示例代码</a>
        </li>
        <li >
            <a href="/redirect/response.php"><i class="icon-file"></i> 交易响应</a>
        </li>
        <li >
            <a href="/redirect/process.php"><i class="icon-file"></i> 流程图示</a>
        </li>
        <li >
            <a href="/redirect/responseCode.php"><i class="icon-file"></i> 响应代码</a>
        </li>
        <li >
            <a href="/redirect/backCode.php"><i class="icon-file"></i> 服务器回调示例代码</a>
        </li>

解决方法:

$(function () {
    $(".navbar-nav").find("li").each(function () {
        var a = $(this).find("a:first")[0];

        var loc = a.pathname.substring(a.pathname.indexOf('/'),a.pathname.lastIndexOf('/'));

        if(loc === location.pathname.substring(a.pathname.indexOf('/'),a.pathname.lastIndexOf('/'))){
            $(this).addClass("active");
        }
        
    $(".nav-list").find("li").each(function () {
        var a = $(this).find("a:first")[0];
        if ($(a).attr("href") === location.pathname) {
            $(this).addClass("active");
        } else {
            $(this).removeClass("active");
        }
    });
})

    没有找到数据。
您需要登录后才可以评论。登录 | 立即注册