JS to achieve the current click a label discoloration, other a label back to primary Colors

Source: Internet
Author: User

When a page has more than a label, and click will jump to the current page, how to achieve the click of the label color highlighting, other tags back to the primary colors.

Use JS to achieve:


Suppose the current page is "1.aspx"

1. Set the value for a label ID:

<a href= "1.aspx?id=1" id= "1" target= "_parent" > "" </a>
<a href= "1.aspx?id=2" id= "2" target= "_parent ">" </a>
<a href= "1.aspx?id=3" id= "3" target= "_parent" > "</a>

2. Write JS method:


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


For other cases, such as clicking on a label page does not jump, you can write this:


<a href= "#" onclick= "Changecss (This)" > "" </a>

<script> 
    function changecss (obj) {
        var alist = document.getElementsByTagName ("a");
        for (var i =0;i < alist. length;i++) {
            Alist[i].style.color = "#000";  Assign primary colors to all a
        tags
        obj.style.color = "#f00";   Make the current tab highlight
    }
        ///Of course, you can also use jquery $ ("a"). Removecss () and addcss () to achieve
</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.