开发者

How to change class="current" location in a list?

im sorry for the poor title, i dont know how to explain it. You see i have already created my panel tabs with the help of <ol>, <li> and css. it is working perfectly but then there is one problem that occured in the program. this tab <li class="current">

the purpose of the class=current that is set in a specified link will help change the background image of the active link. the css code for that is already set and working. I will first show you the codes i used here:

<ol id="toc">
                <li>&nbsp;&nbsp;&nbsp;</li>
                <li class="current"><a href="index.php"><span>#</span></a></li>
                <li><a href="index.php?namelist=a"><span>A</span></a></li>          
                <li><a href="index.php?namelist=b"><span>B</span></a></li>              
                <li><a href="index.php?namelist=c"><span>C</span></a></li>      
                <li><a href="index.php?namelist=d"><span>D</span></a></li>          
                <li><a href="index.php?namelist=e"><span>E</span></a></li>          
                <li><a href="index.php?namelist=f"><span>F</span></a></li>          
                <li><a href="index.php?namelist=g"><span>G</span></a></li>
                <li><a href="index.php?namelist=h"><span>H</span></a></li>          
                <li><a href="index.php?namelist=i"><span>I</span></a></li>              
                <li><a href="index.php?namelist=j"><span>J</span></a></li>              
                <li><a href="index.php?namelist=k"><span>K</span></a></li>      
                <li><a href="index.php?namelist=l"><span>L</span></a></li>      
                <li><a href="index.php?namelist=m"><span>M</span></a></li>                  
                <li><a href="index.php?namelist=n"><span>N</span></a></li>      
                <li><a href="index.php?namelist=o"><span>O</span></a></li>          
                <li><a href="index.php?namelist=p"><span>P</span></a></li>          
                <li><a href="index.php?namelist=q"><span>Q</span></a></li>          
                <li><a href="index.php?namelist=r"><span>R</span></a></li>              
                <li><a href="index.php?namelist=s"><span>S</span></a></li>                  
                <li><a href="index.php?namelist=t"><span>T</span></a></li>          
                <li><a href="index.php?namelist=u"><span>U</span></a></li>              
                <li><a href="index.php?namelist=v"><span>V</span></a></li>  
                <li><a href="index.php?namelist=w"><span>W</span></a></li>          
                <li><a href="index.php?namelist=x"><span>X</span></a></li>          
                <li><a href="index.php?namelist=y"><span>Y</span></a></li>              
                <li><a href="index.php?namelist=z"><span>Z</span></a></li>
                </ol>   

as you can see here is the list of links that i have. its purpose is to search the employee name and information from the database and output in on the next <tr><td> tags where the name of the employee must start with the letter specified in the link list A-Z that were clicked.

now my problem is, the links are called to the same page and does not contain its own php file. from the site that was recommended on me to study, i saw that each linked have its own php file thus the only difference is the location on the class=current example:

if your on A.php

    <ol id="toc">
<li class="current"><a href="A.php"><span>A</span></a></li>         
<li><a href="B.php"><span>B</span></a></li>
</ol>

the link in that page contains the class=current but the other li tags does not, else when clicked on a different link like for example on B.php

<ol id="toc">
<li><a href="A.php"><span>A</span></a></li>         
<li class="current"><a href="B.php"><span>B</span></a></li>
</ol>

the class="current" is in link B.

*NOTE this 2 sets of codes are not what i want. its an example of what i have learned.

but my links does not contain its own php file. all of the links are located in the index.php and are called using the ?namelist="somevalue" inserted before the href "index.php".

what i want for it to happen is on how to change the class="current" location in a certain href whenever the link is clicked. does anyone here knows how to do that that wi开发者_如何学Goll not require to change the htaccess?? thanks for those who will reply :)

MisaChan


Do it manually:

class="<?php echo ($_GET['namelist'] == 'a' ? 'current' : NULL); ?>"
class="<?php echo ($_GET['namelist'] == 'b' ? 'current' : NULL); ?>"
class="<?php echo ($_GET['namelist'] == 'c' ? 'current' : NULL); ?>"
class="<?php echo ($_GET['namelist'] == 'd' ? 'current' : NULL); ?>"

Or do it intelligently:

<?php
foreach (range('a', 'z') as $letter) {
?>
<li class="<?php echo ($_GET['namelist'] == $letter ? 'current' : NULL); ?>"><a href="index.php"><span>#</span></a></li>
<? } ?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜