该<div>下有若干个无法确定数量的<a>标签,我想当点击某按钮的时候,用js将该<div>下的所有<a>的class都改变为"uu"。
ans:
<html>
<head>
<title>test</title>
<style>
.u{color:#f00;}
.uu{color:#00f;}
</style>
<SCRIPT LANGUAGE="JavaScript">
function changeClass(){
var myM1=document.getElementById("m1");
var myClass=myM1.getElementsByTagName("a");
var j=myClass.length;
for (i=0;i<j;i++){
myClass[i].className="uu";
}
}
</SCRIPT>
</head>
<body οnlοad="changeClass()">
<div id="m1">
<a href="1.htm" name="u1" class="u">111</a>
<a href="2.htm" name="u2" class="u">111</a>
<a href="3.htm" name="u3" class="u">111</a>
<a href="4.htm" name="u4" class="u">111</a>
<a href="5.htm" name="u5" class="u">111</a>
<a href="6.htm" name="u6" class="u">111</a>
</div>
</body>
</html>