JS 实现点击a标签的时候让其背景更换

点击a标签的时候给其换背景的方法有很多,在本文将为大家介绍下js是如何实现的,感兴趣的朋友不要错过
代码如下:

<html>
<head>
<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{blue;display:inline;}
</style>
unity3d http://www.unitymanual.com
</head>
<body>
<div class="clMenu">
<span><a href="#">1</a></span>
</div>

</body>
</html>

在alabel.js中:
代码如下:

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";
};
}
};

你可能感兴趣的:(function,display,标签,朋友,background)