要一个简单的dom函数 本帖最后由 mute_solo 于 2010-02-04 16:40:16 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 //胡乱写的~<!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> $('#text li:first').click(function () { $('#text li:not(:first)').css('color', 'red');}); <script>var lis = document.getElementsByTagName('li');for(var i=0;i<lis.length;i++){ lis[i].onclick = function(){ GetTheRestLi(this);}}</script>我需要上面那个函数 得到不是当前节点的li的数组 var lis = document.getElementById('text').getElementsByTagName('li'); $("li").click(function(){ $("#text").children("li").css("color","#ff0000"); $(this).css("color","");}) <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> 请教两个控件数组的问题 求正则表达式,很难哦 JavaScript效果,隐藏IE功能。带图片,知道的进来拿分哦。 用javascript画了一个文本框,但是光标不能选中文字... 多个按钮 点击使其中一个突出显示 jquery如何在.js文件里使用? 怎样实现原生js定时器-模拟右键点击实现轮播效果 在网页中,如何制作根据点击率自动排名? 請教﹕能不能將一個圖片放歪 问题多多。不知何解?(有兴趣的可以看看)日历 js的ie7,8兼容问题? 关于在jsp里面打开一个exe的问题
<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>
$('#text li:not(:first)').css('color', 'red');
});
<script>
var lis = document.getElementsByTagName('li');
for(var i=0;i<lis.length;i++){
lis[i].onclick = function(){
GetTheRestLi(this);
}
}
</script>
我需要上面那个函数 得到不是当前节点的li的数组
$("#text").children("li").css("color","#ff0000");
$(this).css("color","");
})
<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>