日期:2014-05-16  浏览次数:20419 次

3div,点击后排列到最前
HTML code
<a href="#" id="aa">aa</a>
<a href="#" id="bb">bb</a>
<a href="#" id="cc">cc</a>
<div style="width:900px; height:900px;">11</div>
<div style="width:900px; height:900px;">22</div>
<div style="width:900px; height:900px;">33</div>




点击bb, 变成
<div style="width:900px; height:900px;">22</div>
<div style="width:900px; height:900px;">11</div>
<div style="width:900px; height:900px;">33</div>

点击cc,变成
<div style="width:900px; height:900px;">33</div>
<div style="width:900px; height:900px;">11</div>
<div style="width:900px; height:900px;">22</div>

点击后排列到最前



------解决方案--------------------
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript">
function init(){
var a=document.links;
for(var i=0;i<a.length;i++){
a[i].onclick=test;
}
}
function test(){
var divs=[];
var t=document.getElementsByTagName("div");
var p=t[0].parentNode;
for(var i=0;i<t.length;i++){
if(t[i].innerHTML=="11"){
divs[0]=t[i];
}else if(t[i].innerHTML=="22"){
divs[1]=t[i];
}else if(t[i].innerHTML=="33"){
divs[2]=t[i];
}
}
if(this.getAttribute("id")=="aa"){
p.appendChild(divs[0]);
p.appendChild(divs[1]);
p.appendChild(divs[2]);
}else if(this.getAttribute("id")=="bb"){
p.appendChild(divs[1]);
p.appendChild(divs[0]);
p.appendChild(divs[2]);
}else if(this.getAttribute("id")=="cc"){
p.appendChild(divs[2]);
p.appendChild(divs[0]);
p.appendChild(divs[1]);
}
}
window.onload=init;
</script>
</head>

<body>
<a href="#" id="aa">aa</a>
<a href="#" id="bb">bb</a>
<a href="#" id="cc">cc</a>
<div style="width:900px; height:900px; background-color:#F00;">11</div>
<div style="width:900px; height:900px; background-color:#0F0">22</div>
<div style="width:900px; height:900px; background-color:#00F">33</div>
</body>
</html>
这样试试