要一个简单的dom函数

mute_solo 2010-02-04 04:16:48

<ul id="text">
<li>something 1</li>
<li>something 1</li>
<li>something 1</li>
<li>something 1</li>
<li>something 1</li>
</ul>


当我单击第一个列表项的时候 把其余的li都变成红色 我记得jquery里面有个siblings函数,那么javascript下应该怎么写?
...全文
117 12 打赏 收藏 举报
写回复
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
hao_ljp 2010-02-05
  • 打赏
  • 举报
回复

浴火_凤凰 2010-02-04
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 mute_solo 的回复:]
能看清楚再回答吗? 我说是除了当前节点的其他li元素组成的数组
[/Quote]

自己什么都没有做,别人回答了就已经很不错了,还挑剔。
改代码倒是可以的,代码一点没有别人怎么知道你的具体需求啊。
自己的需求只有自己清楚。
byxxw 2010-02-04
  • 打赏
  • 举报
回复

<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>
jeremyxuzz 2010-02-04
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 mute_solo 的回复:]
能看清楚再回答吗? 我说是除了当前节点的其他li元素组成的数组
[/Quote]

----这态度很不友好哈。
fudg1211 2010-02-04
  • 打赏
  • 举报
回复
$("li").click(function(){
$("#text").children("li").css("color","#ff0000");
$(this).css("color","");
})
mute_solo 2010-02-04
  • 打赏
  • 举报
回复
能看清楚再回答吗? 我说是除了当前节点的其他li元素组成的数组
xmliy 2010-02-04
  • 打赏
  • 举报
回复
var lis = document.getElementById('text').getElementsByTagName('li');
mute_solo 2010-02-04
  • 打赏
  • 举报
回复

<script>
var lis = document.getElementsByTagName('li');
for(var i=0;i<lis.length;i++){
lis[i].onclick = function(){
GetTheRestLi(this);
}
}
</script>


我需要上面那个函数 得到不是当前节点的li的数组
mute_solo 2010-02-04
  • 打赏
  • 举报
回复
也许我没说清楚
xmliy 2010-02-04
  • 打赏
  • 举报
回复
$('#text li:first').click(function () {
$('#text li:not(:first)').css('color', 'red');
});
jeremyxuzz 2010-02-04
  • 打赏
  • 举报
回复
//胡乱写的~

<!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>

mute_solo 2010-02-04
  • 打赏
  • 举报
回复
自己往上定一下
相关推荐
发帖
JavaScript

8.7w+

社区成员

Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
帖子事件
创建了帖子
2010-02-04 04:16
社区公告
暂无公告