li类主动自动

时间:2015-02-19 14:31:17

标签: html html-lists

类="有源"自动更改帮助我。

<li>
    <a href="home.php">
    <i class="icon-home"></i>
    <span class="title">Home</span>
    <span class="selected"></span>
    <span class="arrow"></span>
    </a>                    
</li>
<li class="active open">
    <a href="general-settings.php">
    <i class="icon-home"></i>
    <span class="title">General Settings</span>
    <span class="selected"></span>
    <span class="arrow"></span>
    </a>                    
</li>

我可以

home.php页面

<li class="active open">

页面上的general-settings.php

<li class="active open">

实施例

主页

<li active="active open">
        <a href="home.php">
        <i class="icon-home"></i>
        <span class="title">Home</span>
        <span class="selected"></span>
        <span class="arrow"></span>
        </a>                    
</li>

1 个答案:

答案 0 :(得分:0)

尝试使用php

<?php 
$directoryURI = $_SERVER['REQUEST_URI'];
$path = parse_url($directoryURI, PHP_URL_PATH);
$components = explode('/', $path);
$first_part = $components[1];
?>

html部分

<li class="<?php if ($first_part=="home.php") {echo "active open"; }?>">
    <a href="home.php">
    <i class="icon-home"></i>
    <span class="title">Home</span>
    <span class="selected"></span>
    <span class="arrow"></span>
    </a>                    
</li>
<li class="<?php if ($first_part=="general-settings.php") {echo "active open"; }?>">
    <a href="general-settings.php">
    <i class="icon-home"></i>
    <span class="title">General Settings</span>
    <span class="selected"></span>
    <span class="arrow"></span>
    </a>                    
</li>