Js: click a label to highlight the color. Other a labels reply to primary colors _ javascript tips

Source: Internet
Author: User
When a page has multiple a tags, the current click a tag will change color, and the other a tags will return the primary colors. The specific implementation is as follows, if you like it, you can refer to the following: when a page has multiple a tags and will jump to the current page after clicking them, how can you highlight the clicked tags with color changes and reply the primary colors to other tags?

Javascript can be used to achieve:

Assume that the current page is "1. aspx"

1. Set a value for tag:

The Code is as follows:


""
""
""


2. JS writing method:

The Code is as follows:


Script
& (Document). ready (function (){
Var id = windows. ulr. substring (windows. ulr. IndeOf ("? Id = "), 1) // obtain the id value
Var currtA = document. getElementById (id); // obtain the currently clicked a tag
If (currtA! = Null)
CurrtA. style. color = "# f00 ";
});
Script


In other cases, if you click the tab page and do not jump to it, you can write as follows:

The Code is as follows:


""

Script
Function changeCss (obj ){
Var alist = document. getElementsByTagName ("");
For (var I = 0; I <alist. Length; I ++ ){
Alist [I]. style. color = "#000"; // assign primary colors to all a labels
}
Obj. style. color = "# f00"; // highlight the current tag
}
// Of course, you can also use Jquery's $ ("a"). removeCss () and addCss () to implement
Script

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.