PHP - 突出显示选定的链接
如何“突出显示”(变成不同的颜色、加粗等等……)已单击的链接?
示例如下: 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>
How do I "highlight" (turn to a different color, make bold, whatever..) a link that has been clicked on?
Example is here: http://www.celebrything.com/
Trying to get the Today, Week, and Month links in the right sidebar to turn a different color once clicked.
Here's the code I'm using to show the results in the right sidebar:
<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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
CSS 可以做到这一点。
如果某个链接在任何时候被访问过:
如果该链接具有焦点:
注意: IE7 及更低版本不支持
:focus
。请参阅 CSS 内容和浏览器兼容性 和:focus
。CSS can do this.
If a link has been visited at any point:
If the link has focus:
Note: IE7 and lower don't support
:focus
. See CSS contents and browser compatibility and:focus
.如果您询问如何使当前页面处于活动状态,那么您可以这样做:
并且您将需要在 css 中添加 .selected 类并将其样式设置为您想要的任何样式,也许是这样的:
If your asking howto make the current page active here is how you can do it:
And you will need to add the .selected class in your css and style it to whatever you want, maybe something like this: