首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

怎么给一个DIV层加一个按钮(层在页面底部),点击这个按钮,这个层最小化

2012-01-09 
如何给一个DIV层加一个按钮(层在页面底部),点击这个按钮,这个层最小化如何给一个DIV层加一个按钮(层在页面

如何给一个DIV层加一个按钮(层在页面底部),点击这个按钮,这个层最小化
如何给一个DIV层加一个按钮(层在页面底部),点击这个按钮,这个层最小化,比如原来是宽100*高80,现在缩成宽100*高10,只露出一点,再点击这个按钮,再恢复成原来大小。希望给个最简化的代码。谢谢!

[解决办法]
可以分成2个DIV做啊....一个控制另外一个的display属性不就好了
下面的例子是我自己写的 将就下啦

HTML code
<html>    <head>        <style type="text/css">            #2{                background-color: red;                width:200px;                height:20px;            }            #3{                background-color: black;                width:200px;                height:300px;            }        </style>        <script type="text/javascript">            function method1(){                var div = document.getElementById("3");                if(div.style.display == "none"){                    div.style.display = "block";                }else{                    div.style.display = "none";                }            }        </script>    </head>    <body>        <div id="1">            <div id="2">                <input type="button" value="点击这里" onclick="method1()">            </div>            <div id="3">            </div>        </div>    </body></html>
[解决办法]
<html>
<head>
<title>Test</title>
<script>
var flag = 0;
function test() {
if(flag == 0) {
flag = 1;
document.getElementById("div_id").style.width = "100"; //你想把div设为多大就在这改为多大
document.getElementById("div_id").style.height = "100";
}else {
flag = 0;
document.getElementById("div_id").style.width = "1000";
document.getElementById("div_id").style.height = "800";
}
}
</script>
<head>

<body>
<div id="div_id" style="width:1000; height:800; background-color:#CCEEF2">
<input type="button" value="按钮" onclick="test()">
</div>
</body>
</html>


把上面找码直接考过去就能看到效果

热点排行