请教帮忙修改个javascript

来源:百度知道 编辑:UC知道 时间:2024/06/20 21:10:53
<!--
var Ptr=document.getElementsByTagName("li");
function $() {
for (i=1;i<Ptr.length+1;i++) {
Ptr[i-1].className = (i%2>0)?"t1":"t2";
}
}
window.onload=$;
for(var i=0;i<Ptr.length;i++) {
Ptr[i].onmouseover=function(){
this.tmpClass=this.className;
this.className = "t3";

};
Ptr[i].onmouseout=function(){
this.className=this.tmpClass;
};
}
//-->

用于网页的各行变色的,但是这样 所有LI都变色了。我只想特定某个CLASSNAME 才会变色 要怎么编写?

<html>

<head>
<style>
.t1{
background-color : red ;}
.t2{
background-color : black ;}
.t3{
background-color : blue ;}
</style>
<title></title>

</head>

<body>
<ul class="bbb">
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
</ul>
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
</ul>
</body>
<script language="javascript" type="text/javascript">
<!--
var Ptr=document.getElementsByTagName("li");
function $() {
for (i=1;i<Ptr.length+1;i++) {
if(Ptr[i-1].parentElement.className=="bbb"){//加上这行判段父元素为某个classname才进行操作

Ptr[i-