DIV的显示与隐藏高手告诉下怎么写

来源:百度知道 编辑:UC知道 时间:2024/05/31 00:44:32
我做了3个表格把他们放在了一个大表格里给这个3个小表格套上了层 我想点击第一个层对应的按钮显示第一个层点击第二个层显示第二个层隐藏其他的层那些代码怎么写啊!高手写详细点我新手 谢谢拉!好的一定追分!

很简单,随便给你做个例子

<script>
function hide(){
document.getElementById("div1").style.display="none"
document.getElementById("div2").style.display="none"
document.getElementById("div3").style.display="none"
}
function show(id){
hide()
document.getElementById(id).style.display="block"
}
</script>

<input type="button" value="div1" onclick="show('div1')"/>

<input type="button" value="div2" onclick="show('div2')"/>

<input type="button" value="div3" onclick="show('div3')"/>
<div id="div1" style="height:50px;width:50px;background-color:red"></div>
<div id="div2" style="height:50px;width:50px;background-color:blue"></div>