0

私はこのスクリプトを機能させようとしていますが、残念ながら何もすることはありません...それを行うためのより良い方法もあると思いますが、どれがわかりませんか?

開いたページでボタンをホバーしたままにしたいので、ボタンのホバーのように見えるクラスを作成し、現在のページ名が「このボタン」リンクに対応する場合、このクラスを適用するようにphpに言いました。

$currentpath = basename(__FILE__);

header.php をインクルードする前に各ページに設定されています

ありがとうございました!

PHP と HTML:

<?h
$o = "/ita/o.h";
$ = "/ita/.h";
$a = "/ita/a.h";
$s = "/ita/s.h";
$st = "/ita/st.h";
$p = "/ita/p";
$t = "/ita/t";
$c = "/ita/c";
?>

<div id="button"> 
  <ul> 
    <li><a href=<?=$o?> class="<?php if($currentpath == basename($o)){echo("buttonon");} ?>">o</a></li>
    <li><a href=<?=$p?> class="<?php if($currentpath == basename($p)){echo("buttonon");} ?>">p</a></li>
    <li><a href=<?=$a?> class="<?php if($currentpath == basename($a)){echo("buttonon");} ?>">a</a></li>
    <li><a href=<?=$s?> class="<?php if($currentpath == basename($s)){echo("buttonon");} ?>">s</a></li>
    <li><a href=<?=$st?> class="<?php if($currentpath == basename($st)){echo("buttonon");} ?>">st</a></li>
    <li><a href=<?=$p?> class="<?php if($currentpath == basename($p)){echo("buttonon");} ?>">p</a></li>
    <li><a href=<?=$t?> class="<?php if($currentpath == basename($t)){echo("buttonon");} ?>">t</a></li>
    <li><a href=<?=$c?> class="<?php if($currentpath == basename($c)){echo("buttonon");} ?>">c</a></li>
  </ul> 
</div>  

CSS:

#button ul { 
        margin: 0;
        padding: 0; 
        list-style-type: none; 
        text-align: center; 
        background-color: #F00;
} 
#button ul li {  
        display: inline; 
} 
#button ul li a { 
        display:inline-block;
        color:#FFF;
        font-family:Calibri;
        font-size:18px;
        font-weight:bold;
        padding:4px 15px 4px 15px;
        text-decoration:none;
        font-variant:small-caps;
} 
#button ul li a:hover { 
        background-color:#F00;
        color:#02346F;
        padding:4px 15px 4px 15px;
        font-size:18px;
        font-weight:bolder;
}

.buttonon { 
        background-color:#F00;
        display:inline-block;
        font-family:Calibri;
        font-size:18px;
        font-weight:bold;
        text-decoration:none;
        font-variant:small-caps;
        color:#02346F;
        padding:4px 15px 4px 15px;
        font-size:18px;
        font-weight:bolder;
}

編集: $currentpath の定義を追加しました。

4

1 に答える 1

0

$currentpathそれがコードの他の場所で定義されていると仮定します:

サブディレクトリがあり、basename() がサブディレクトリを返さないため、basename() を使用しても機能しません。

部分文字列を検索できます。

<?php if(strpos($currentpath, $prezzi) !== false){echo("buttonselected");} ?>
于 2013-01-23T21:52:37.960 に答える