JS Implementation Click a label when the background to replace _javascript tips

Source: Internet
Author: User
Copy Code code as follows:

<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<title></title>
<script type=text/javascript src= "Alabel.js" ></script>
<style type= "Text/css" >
. Curr{background:blue;display:inline;}
</style>

<body>
<div class= "Clmenu" >
<span><a href= "#" >1</a></span>
</div>

</body>

In the Alabel.js:
Copy Code code as follows:

Window.onload = function ()
{
var Aspan = document.getElementsByTagName ("span");
var i = 0;
for (i = 0; i < aspan.length; i++)
{
Aspan[i].onclick = function ()
{
for (i = 0; i < aspan.length i++) Aspan[i].classname = "";
This.classname = "Curr";
};
}
};

This enables you to add a red background to a label when you click it.

Note: The display in the Curr attribute cannot be block, otherwise the added background is an entire line.

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.