简体   繁体   English

如何更改访问链接的背景颜色

[英]How to change background color for visited link

I have the following code: 我有以下代码:

<td bgcolor="#FF0000"><center>
    <? echo $rows['msisdn']; ?>
</td>
<td align="center" bgcolor="#FFFFFF">
    <a href="control_clientinfo.php?member_id=<? echo $rows['member_id']; ?>"
    class="update">Look Up</a>
</td>

This draws data from mysql for me and does what it needs to do, question 这为我从mysql提取数据,并做了它需要做的事情,问题

<td bgcolor="#FF0000">
    <center>
    <? echo $rows['msisdn']; ?>
</td>

How do I change that background colour once the link has been visited. 访问链接后,如何更改背景颜色。 I know how to change the visited link colour but i want to change the table viewed colour. 我知道如何更改访问的链接颜色,但我想更改表格查看的颜色。

Is this possible or am I biting into a rock? 这可能吗?还是我要咬石头?

Updated Answer 更新的答案

The browser controls the visited link status, there's no way to determine this with Javascript or CSS for the security of users. 浏览器控制访问的链接状态,无法通过Javascript或CSS来确定,以确保用户安全。 This may have worked in the past, but no longer works on all modern web browsers. 这可能在过去有效,但已不再在所有现代Web浏览器上有效。 -- This is done to prevent history tracking by the browsers themselves. -这样做是为了防止浏览器自己跟踪历史记录。 The only workaround for this would be to track which links were clicked using Javascript event handlers and if you want this information persistant across multiple page-loads/refreshes, you'll need to set a cookie. 唯一的解决方法是跟踪使用Javascript事件处理程序单击了哪些链接,如果您希望此信息在多个页面加载/刷新之间持久存在,则需要设置一个cookie。

For current page, you could use Javascript (or better yet, jQuery) to change the color of your background. 对于当前页面,您可以使用Javascript(或更好的jQuery)来更改背景颜色。

Using jQuery: 使用jQuery:

$("td a").click(function() {
    $(this).parent("td").addClass('clicked');
});

On a related note, I highly recommend NOT using <center> and the bgcolor and align attributes. 在相关说明中,我强烈建议不要使用<center>以及bgcoloralign属性。 Those have long been deprecated in recent HTML versions. 长期以来,在最近的HTML版本中已不推荐使用这些功能。 Consider using CSS for all of your "center" and styling/background color needs. 考虑将CSS用于所有“中心”和样式/背景颜色需求。

Nothing much to do with PHP I'm afraid, more of a Javascript problem. 恐怕与PHP无关,更多的是Javascript问题。

Try Remy Sharp's jQuery plugin http://remysharp.com/2008/02/25/visited-plugin/ 试试雷米·夏普(Remy Sharp)的jQuery插件http://remysharp.com/2008/02/25/visited-plugin/

Identical code is in this answer https://stackoverflow.com/a/1791790/932508 相同的代码在此答案中https://stackoverflow.com/a/1791790/932508

Add onclick function in table column with anchor tag 使用锚标记在表列中添加onclick函数

<td align="center" bgcolor="#FFFFFF" onclick="document.getElementById("demo").style.backgroundColor="RED";"> <a href="control_clientinfo.php?member_id=<? echo  $rows['member_id']; ?>" class="update">Look Up</a></td>

Then add an Id tag to other table column for which you want to change background color. 然后将一个ID标记添加到要更改其背景颜色的其他表列。

<td id="demo" bgcolor="#FF0000">
  <center>
  <? echo $rows['msisdn']; ?>
  </center>
</td>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM