0

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

示例在这里: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>
4

2 回答 2

5

CSS 可以做到这一点。

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

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

如果链接有焦点:

a:focus { color: red; }

注意: IE7 及更低版本不支持:focus. 请参阅CSS 内容和浏览器兼容性以及:focus.

于 2009-12-12T01:16:13.177 回答
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>
于 2009-12-12T01:21:16.003 回答