Js click the implementation code of the list text corresponding to the line that shows the background color, js background color
This example describes how to display the background color of a javascript click list text line. Share it with you for your reference. The details are as follows:
JS controls li. When you click the mouse, the class is automatically added to generate a special webpage effect for the list text.
Run the following command:
<Style type = "text/css"> li {cursor: pointer ;}. cur {background: red ;}</style> <script type = "text/javascript"> window. onload = function () {var aLi = document. getElementsByTagName ("li"); var I = 0; for (I = 0; I <aLi. length; I ++) {aLi [I]. onclick = function () {for (I = 0; I <aLi. length; I ++) aLi [I]. className = ""; this. className = "cur ";};}}; </script> <div class = "clMenu"> <ul> <li> 1 </li> <li> 2 </li> <li> 4 </li> <li> 5 </li> </ul> </div>
I hope this article will help you design javascript programs.