Home > Web Front-end > JS Tutorial > Js implements the current click on the a label to change color and highlight other a labels to return to the original color_javascript skills

Js implements the current click on the a label to change color and highlight other a labels to return to the original color_javascript skills

WBOY
Release: 2016-05-16 17:12:11
Original
1648 people have browsed it

When a page has multiple a tags, and when clicked, it will jump to the current page. How can the clicked tag change color and be highlighted, and other tags return to their original colors?

Use JS to achieve:

Assume the current page is "1.aspx"

1. Set the value of a tag ID:

Copy code The code is as follows:

""
""
""

2. Write JS method:
Copy code The code is as follows:

<script> <br>&(document).ready (function(){ <br>var id = windows.ulr.substring(windows.ulr.IndeOf("?id="),1) //Get the id value<br>var currtA = document.getElementById(id); //Get the currently clicked a tag <br>if(currtA != null) <br>currtA.style.color = "#f00"; <br>}); <br></script>

For other situations, such as clicking the a tag page without jumping, you can write like this:
Copy code Code As follows:

""

<script> <br>function changeCss(obj){ <br>var alist = document.getElementsByTagName("a"); <br>for(var i =0;i < alist.Length;i ){ <br>alist[i].style. color = "#000"; //Assign primary color to all a tags<br>} <br>obj.style.color = "#f00"; //Highlight the current tag<br>} <br>//Of course You can also use Jquery's $("a").removeCss() and addCss() to achieve <br></script>
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template