【问题标题】:PHP - Highligh selected linkPHP - 突出显示选定的链接
【发布时间】:2010-12-25 21:34:18
【问题描述】:

我如何“突出显示”(变成不同的颜色,加粗,等等)一个被点击的链接?

示例在这里:http://www.celebrything.com/ 尝试在右侧栏中获取“今天”、“周”和“月”链接,以便在单击后变为不同的颜色。

这是我用来在右侧边栏中显示结果的代码:

<div id="sidebar">

<div class="post">
<h2>

<font color="#333333">Top 50 Celebrities</font>
<br>
<br>
<font color="#333333"><a href="index.php?table=today">Today</a></font>
<font color="#333333"><a href="index.php?table=week">Week</a></font>
<font color="#333333"><a href="index.php?table=month">Month</a></font>
</font>
<br>
<br>

<?php

function showTable ($table){

if (!in_array($table, array('today', 'week', 'month'))) {
  return false;
}

global $wpdb;
$result = $wpdb->get_results('SELECT name, count FROM wp_celebcount_' . $table);
foreach($result as $row) {
echo '<a href="http://www.celebrything.com/?s=' .
    urlencode($row->name) . '&search=Search">' . $row->name .
    '</a> - ' . $row->count . ' Posts<br/>';
}
}


if (!empty($_GET['table'])) {
showTable($_GET['table']);

} else { showTable('today'); }

?>




</h2>
</div>

</div>

<div class="clear"></div>

【问题讨论】:

    标签: php css hyperlink highlighting


    【解决方案1】:

    如果您在此处询问如何使当前页面处于活动状态,您可以这样做:

    <font color="#333333"><a class="<?php echo currentPage('today') ?>" href="index.php?table=today">Today</a></font>
    <font color="#333333"><a class="<?php echo currentPage('week') ?>" href="index.php?table=week">Week</a></font>
    <font color="#333333"><a class="<?php echo currentPage('month') ?>"href="index.php?table=month">Month</a></font>
    
    
    function currentPage($isTableSet)
    {
        if($_GET['table'] == $isTableSet)
            return 'selected'
        else
            return '';
    }
    

    你需要在你的 CSS 中添加 .selected 类并将其设置为任何你想要的样式,可能是这样的:

    <style type="text/css">
        .selected  {
            font-weight: bold;
        }
    </style>
    

    【讨论】:

      【解决方案2】:

      CSS 可以做到这一点。

      如果在任何时候访问过链接:

      <style type="text/css">
      a:visited { color: red; }
      </style>
      

      如果链接有焦点:

      a:focus { color: red; }
      

      注意: IE7 及更低版本不支持:focus。见CSS contents and browser compatibility:focus

      【讨论】:

        猜你喜欢
        • 2011-12-24
        • 1970-01-01
        • 2013-09-14
        • 1970-01-01
        • 1970-01-01
        • 2014-07-09
        • 2014-12-07
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多