8.7w+
社区成员
<ul id="text">
<li>something 1</li>
<li>something 1</li>
<li>something 1</li>
<li>something 1</li>
<li>something 1</li>
</ul>
<ul id="text">
<li>something 1</li>
<li>something 2</li>
<li>something 3</li>
<li>something 4</li>
<li>something 5</li>
</ul>
<script>
function changeColor(){
this.id = "text";
this.childs = null;
this.init = function(){
if(this.childs == null)
this.childs = document.getElementsByTagName("li");
this.bind(this.change);
}
this.change = function(c,tobj){
for(var i=0;i<tobj.length;i++){
if(c != tobj[i]){
tobj[i].style.color = "#990000";
}
else{
c.style.color = "#000000";
}
}
}
this.bind = function(callback){
if(this.childs == null){
alert("childs is null");
return;
}
var ot = this;
for(var i=0;i<this.childs.length;i++){
this.childs[i].onclick = function(){
callback(this,ot.childs);
}
}
}
}
var cObj = new changeColor();
cObj.init();
</script>
$("li").click(function(){
$("#text").children("li").css("color","#ff0000");
$(this).css("color","");
})
<script>
var lis = document.getElementsByTagName('li');
for(var i=0;i<lis.length;i++){
lis[i].onclick = function(){
GetTheRestLi(this);
}
}
</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> new document </title>
<meta name="generator" content="editplus" />
<meta name="author" content="" />
<meta name="keywords" content="" />
<meta name="description" content="" />
</head>
<body>
<ul id="text">
<li>something 1</li>
<li>something 2</li>
<li>something 3</li>
<li>something 3</li>
<li>something 5</li>
</ul>
<script>
var lis= document.getElementById('text').childNodes;
var lastLi=null;
for(var i=0;i<lis.length;i++)
{
lis[i].style.backgroundColor='silver';
lis[i].onclick=function(event){
if(null!=lastLi)
{
lastLi.style.backgroundColor='silver';
}
this.style.backgroundColor='red';
lastLi=this;
};
}
</script>
</body>
</html>