通过php设置z-index和class的问题

时间:2013-12-11 18:17:14

标签: php html css if-statement echo

我有一些php代码,用于在头文件中设置菜单中不同选项卡选项的z-index和类。头文件包含在每个页面中,然后此代码将确定哪个选项卡处于活动状态,因此可以更改z索引和css。我的问题是这个代码,无论$ url等于什么,都给home选项卡提供了一个z-index为1000和一类“active tab”。在我看来,我的if语句中包含所有内容,是否有人知道为什么它不会检测到say,documentation.php并将1000 z-index应用于此?

<?php

  $zi_home = "10";
  $zi_ss = "10";
  $zi_tes = "10";
  $zi_order = "10";
  $zi_con = "10";

  $tab_home = "inactive-tab";
  $tab_ss = "inactive-tab";
  $tab_tes = "inactive-tab";
  $tab_order = "inactive-tab";
  $tab_con = "inactive-tab";

    $url = $_SERVER['REQUEST_URI'];

  if ($url = "/index.php") {
         $zi_home = "1000";
         $tab_home = "active-tab";
    } elseif ($url = "/documentation.php") {
         $zi_ss = "1000";
         $tab_ss = "active-tab";
    } elseif ($url = "/order.php") {
         $zi_tes = "1000";
         $tab_tes = "active-tab";
    } elseif ($url = "/about.php") {
         $zi_order = "1000";
         $tab_order = "active-tab";
    } elseif ($url = "/contactus.php") {
         $zi_con = "1000";
         $tab_con = "active-tab";
 }    

?>

header.php文件摘要:

        <div class="<? echo $tab_home; ?>" style="z-index: <? echo $zi_home; ?>;">
            <a href = "index.php">Home</a>
        </div>

        <div class="<? echo $tab_ss; ?>" style="z-index: <? echo $zi_ss; ?>;">
            <a href = "documentation.php">Documentation</a>
        </div>

1 个答案:

答案 0 :(得分:3)

你使用=而不是==。如果你改变它们看起来它会起作用。应该是:

if ($url == "/index.php") {
     $zi_home = "1000";
     $tab_home = "active-tab";
} elseif ($url == "/documentation.php") {
     $zi_ss = "1000";
     $tab_ss = "active-tab";
} elseif ($url == "/order.php") {
     $zi_tes = "1000";
     $tab_tes = "active-tab";
} elseif ($url == "/about.php") {
     $zi_order = "1000";
     $tab_order = "active-tab";
} elseif ($url == "/contactus.php") {
     $zi_con = "1000";
     $tab_con = "active-tab";
}