2014-03-26 29 views
0

我有一個sidebar-right.html文件,它具有以下元素的側欄。如何使用php包含文件將活動類添加到元素

<div class="col-sm-2"> 
    <div class="list-group"> 
    <a href="Sub-Investment.php" class="list-group-item">New investment plan</a> 
    <a href="open-creditcard.php?action=credit" class="list-group-item">Apply credit card</a> 
    <a href="open-creditcard.php?action=limit" class="list-group-item">Increase credit limit</a> 
    </div> 
</div> 
</div> 
</div> 
</div> 

我叫這個頁面在另一個文件名爲open-creditcard.php 使用include "..\View\\sidebar-right.html";

所以我對這個網頁的最終網址將是這樣的:
http://localhost/obis/Controller/open-creditcard.php?action=limithttp://localhost/obis/Controller/open-creditcard.php?action=credit

我想補充一類active動態使用php,在sidebar-right.html中的列表組。

我想是這樣的:
<a href="open-creditcard.php?action=credit" class="list-group-item" <?php if($_SERVER['PHP_SELF'] == "/open-creditcard.php?action=credit") echo 'class="list-group-item active"'; ?>>Apply credit card</a>
但它不工作。有什麼我想念?有誰能夠幫助我?

回答

1

$_SERVER['PHP_SELF']不包括查詢字符串,但你可以使用$_GET['action']代替:

<a href="open-creditcard.php?action=credit" class="list-group-item<?= isset($_GET['action']) && $_GET['action'] == 'credit' ? ' active' : '' ?>">Apply credit card</a> 
<a href="open-creditcard.php?action=limit" class="list-group-item<?= isset($_GET['action']) && $_GET['action'] == 'limit' ? ' active' : '' ?>">Increase credit limit</a> 
+0

非常感謝。它運作良好! – user1012181

+0

我們如何動態更改頁面的標題? – user1012181

-1
<a href="open-creditcard.php?action=credit" class="list-group-item<?= isset($_GET['action']) && $_GET['action'] == 'credit' ? ' active' : '' ?>">Apply credit card</a> 
<a href="open-creditcard.php?action=limit" class="list-group-item<?= isset($_GET['action']) && $_GET['action'] == 'limit' ? ' active' : '' ?>">Increase credit limit</a> 
相關問題