PHP - 突出显示选定的链接

标签 php css hyperlink highlighting

我如何“突出显示”(变成不同的颜色,加粗,诸如此类……)已被点击的链接?

示例在这里: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 contents and browser compatibility:focus .

关于PHP - 突出显示选定的链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1891853/

相关文章:

css - 仅在 Firefox 中为空白

html - jQuery IMG Slider - 幻影边距

单击链接时 PHP 执行文件两次

php - 获取 PHP openssl_encrypt 方法/模式列表

php - 在MySQL数据库中创建PHP缓存系统?

javascript - 如何使用 jQuery 循环访问 WordPress WP_Query 对象?

php - 从多个复选框中删除过程错误

javascript - flex 元素是否有可能与它们上方的元素紧密对齐?

html - 需要帮助修复链接的可点击区域

HTML 图像扩展更远并阻止链接