4个回答
展开全部
把以下代码保存成html文件再浏览器就能看到效果了
<div style="position:absolute; top:100px; left:100px; width:100px; height:100px; background-color:#FF0000; z-index:1;" onclick="changeZindex(this);">1</div>
<div style="position:absolute; top:100px; left:150px; width:100px; height:100px; background-color:#3333FF; z-index:2;" onclick="changeZindex(this);">2</div>
<div style="position:absolute; top:150px; left:100px; width:100px; height:100px; background-color:#990099; z-index:3;" onclick="changeZindex(this);">3</div>
<div style="position:absolute; top:150px; left:150px; width:100px; height:100px; background-color:#336600; z-index:4;" onclick="changeZindex(this);">4</div>
<script language="javascript">
function changeZindex(obj){
var divs = document.getElementsByTagName("DIV");
var maxNum = 0;
for(var i = 0; i < divs.length; i++){
var tempNum = divs[i].style.zIndex;
tempNum = (tempNum) ? parseInt(tempNum) : 0;
if(tempNum > maxNum) maxNum = tempNum;
}
obj.style.zIndex = maxNum + 1;
}
</script>
<div style="position:absolute; top:100px; left:100px; width:100px; height:100px; background-color:#FF0000; z-index:1;" onclick="changeZindex(this);">1</div>
<div style="position:absolute; top:100px; left:150px; width:100px; height:100px; background-color:#3333FF; z-index:2;" onclick="changeZindex(this);">2</div>
<div style="position:absolute; top:150px; left:100px; width:100px; height:100px; background-color:#990099; z-index:3;" onclick="changeZindex(this);">3</div>
<div style="position:absolute; top:150px; left:150px; width:100px; height:100px; background-color:#336600; z-index:4;" onclick="changeZindex(this);">4</div>
<script language="javascript">
function changeZindex(obj){
var divs = document.getElementsByTagName("DIV");
var maxNum = 0;
for(var i = 0; i < divs.length; i++){
var tempNum = divs[i].style.zIndex;
tempNum = (tempNum) ? parseInt(tempNum) : 0;
if(tempNum > maxNum) maxNum = tempNum;
}
obj.style.zIndex = maxNum + 1;
}
</script>
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
document.getElementById('显示的div-ID').style.zIndex=100000;()
document.getElementById('其他的div-ID').style.zIndex=1;()
document.getElementById('其他的div-ID').style.zIndex=1;()
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
<div id="div_id"></div>
document.getElementById('div_id').style.z-index=1000;
document.getElementById('div_id').style.z-index=1000;
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
JQ:
<div id="test">
<div id="t1"></div>
<div id="t2"></div>
<div id="t3"></div>
<div id="t4"></div>
<div id="t5"></div>
</div>
$(function(){
$("#test div").click(function(){
$(this).css("zIndex","9999").siblings().css("zIndex","1000");
});
});
<div id="test">
<div id="t1"></div>
<div id="t2"></div>
<div id="t3"></div>
<div id="t4"></div>
<div id="t5"></div>
</div>
$(function(){
$("#test div").click(function(){
$(this).css("zIndex","9999").siblings().css("zIndex","1000");
});
});
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询