使用JS单击时更改超链接颜色 [英] Changing hyperlink color when clicked using JS

查看:697
本文介绍了使用JS单击时更改超链接颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我是JS新手。请帮我解决以下问题。


在页面顶部考虑3个链接,如link1,link2,link3,灰色。单击每个链接时,相应的数据应显示在同一页面的底部,当前选定的链接应更改为橙色。

假设如果选择了link1,则link1的颜色应更改为橙色和其他2个链接应保持灰色。如果单击另一个链接,相应的链接应更改为橙色,其他2链接应变为灰色。我正在尝试使用JS中的onclick事件。但我没有成功。请建议我如何解决这个问题。


请将解决方案发送到**** [删除邮箱]


问候,

Arun

解决方案

欢迎来到TSDN!


使用style.color设置文本颜色。


发布到目前为止的代码。


试试这个链接:

http://www.goldcoastwebdesigns.com/c...nk-color.shtml


超链接和CSS

使用CSS更改链接颜色的一些简单方法。颜色也可以用HTML控制,但这不会提供很大的灵活性。


简介

以下是一些更改和控制超链接颜色的方法。通过在HTML中添加样式表并编辑以下Anchor Pseudo-classes,可以使超链接更改颜色:

链接:未访问链接的颜色。

访问量:访问过的链接的颜色。

活动:点击链接时的颜色。当用户在访问链接目标后点击后退按钮时,链接将保持该颜色。

悬停:鼠标悬停在链接上时链接的颜色。

使用内部样式表更改超链接颜色

在不引用外部样式表的情况下将CSS添加到HTML文档

如果您只需要在一个页面上更改颜色,则可以使用此代码。如果您使用此代码创建许多页面,然后发现您需要再次更改颜色,它可能会成为一项重要工作。


如果您打算构建许多网页,建议您创建外部样式表并将HTML文档链接到该页面。这样,如果您需要再次更改颜色,您只需将值更改为一个文件 - 外部样式表,更改将在无限数量的页面中生效。


将以下CSS代码添加到HTML文档的head部分:< head> code< / head>并根据需要更改颜色值:


代码

展开 | 选择 | 换行 | 行号


< blockquote>


试试这个链接:

http://www.goldcoastwebdesigns.com/c...nk-color.shtml


超链接和CSS



这显然是使用CSS,而不是JavaScript。


Hi,

Iam new to JS. Kindly help me to solve the following difficulty.

Consider 3 links such as link1,link2,link3 in gray color at top of the page. When each link is clicked the corresponding data should get displayed at the bottom of the same page and the currently selected link should change to orange.
Suppose if link1 is selected, the color of link1 should change to orange and other 2 link should remain in gray color. If onother link is clicked the corresponding link should change to orange and other 2 link should turn to gray. I was trying this with onclick event in JS. But i was not successful in that. Kindly suggest me how to solve this problem.

Kindly send the solutions to **** [removed email]

Regards,
Arun

解决方案

Welcome to TSDN!

Use style.color to set the text colour.

Post the code you have so far.


try this link:

http://www.goldcoastwebdesigns.com/c...nk-color.shtml

Hyperlinks and CSS
Some simple ways of changing link colors with CSS. Colors can can also be controled with HTML but this does not offer much flexibility.


Introduction
Here is a few ways to change and control the color of hyperlinks. Hyperlinks can be made to change colors by adding a style sheet to your HTML and editing the following Anchor Pseudo-classes:
Link: The color of an un-visited link.
Visited: The color of a visited link.
Active: The color of the link when it is clicked. The link will remain that color when users hit the Back Button after visiting the link destination.
Hover: The color of the link when the mouse hovers over it.

Change Hyperlink Color with Internal Style Sheet
Adding CSS to a HTML Document without Referencing an External Style Sheet
If you need to change colors on one page only, this code can be used. It can become a big job if you use this code to create many pages, then discover that you need to change the color again.

If you intend to build many web pages, it is suggested to create an external style sheet and link your HTML documents to that. This way, if you need to change colors again, all you have to do is change the values to just one file - the external style sheet, and changes will take effect across an unlimited number of pages.

Add the following CSS code into the head section of your HTML document: <head>code</head> and change the color values as required:

Code

Expand|Select|Wrap|Line Numbers


try this link:

http://www.goldcoastwebdesigns.com/c...nk-color.shtml

Hyperlinks and CSS

That''s obviously using CSS, not JavaScript.


这篇关于使用JS单击时更改超链接颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆