Mik*_*ike 0 css php highlighting hyperlink
如何"突出显示"(转向不同的颜色,制作粗体,等等......)已被点击的链接?
示例如下: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>
CSS可以做到这一点.
如果在任何时候访问过链接:
<style type="text/css">
a:visited { color: red; }
</style>
如果链接具有焦点:
a:focus { color: red; }
注意: IE7及更低版本不支持:focus.见CSS内容和浏览器的兼容性和:focus.