在jsp页面中,我有两个div。首先显示第一个div,当我点击一个按钮后,我在显示第二个div,求大神给源代码

很急。

<html>
    <head>
        <style type="text/css">
            * {
            padding - bottom: 0px;
            margin: 0px;
            padding - left: 0px;
            padding - right: 0px;
            font - size: 12px;
            padding - top: 0px;
        }
        body {
            padding - left: 20px;
            padding - top: 20px;
        }
        .wid240 {
            width: 242px;
            margin - bottom: 20px;
        }
        .wid180 {
            width: 182px;
        }
        .tab {
            border - bottom: #000 1px solid;
            border - left: #000 1px solid;
            border - top: #000 1px solid;
            border - right: #000 1px solid;
        }
        .tab UL {
            zoom: 1;
            clear: both;
        }
        .tab UL: after {
            display: block;
            height: 0px;
            visibility: hidden;
            clear: both;
            content: "";
        }
        .tab UL LI {
            text - align: center;
            line - height: 26px;
            width: 60px;
            display: inline;
            background: #000;
            float: left;
            height: 26px;
            color: #fff;
        }
        .tab UL LI.on {
            background: #fff;
            color: #000;
        }
        .tabList {
            border - bottom: #000 1px solid;
            border - left: #000 1px solid;
            height: 150px;
            border - top: #000 1px;
            border - right: #000 1px solid;
        }
        .tabList.one {
            padding - bottom: 10px;
            padding - left: 10px;
            padding - right: 10px;
            display: none;
            color: #ff0000;
            padding - top: 10px;
        }
        .tabList.block {
            display: block;
        }
         </style>
        <script type="text/javascript">
            function setTab(name, m, n) {
                for (var i = 1; i <= n; i++) {
                    var menu = document.getElementById(name + i);
                    var showDiv = document.getElementById("cont_" + name + "_" + i);
                    menu.className = i == m ? "on": "";
                    showDiv.style.display = i == m ? "block": "none";
                }
            }
        </script>
        <meta name="GENERATOR" content="MSHTML 8.00.7600.16535">
    </head>
    <body>
        <div class="wid240">
            <div class="tab">
                <ul>
                    <li id="one1" class="on" onmouseover='setTab("one",1,4)'>
                        one1
                    </li>
                    <li id="one2" onmouseover='setTab("one",2,4)'>
                        one2
                    </li>
                    <li id="one3" onmouseover='setTab("one",3,4)'>
                        one3
                    </li>
                    <li id="one4" onmouseover='setTab("one",4,4)'>
                        one4
                    </li>
                </ul>
            </div>
            <div class="tabList">
                <div id="cont_one_1" class="one block">
                    cont_one_1
                </div>
                <div id="cont_one_2" class="one">
                    cont_one_2
                </div>
                <div id="cont_one_3" class="one">
                    cont_one_3
                </div>
                <div id="cont_one_4" class="one">
                    cont_one_4
                </div>
            </div>
        </div>
        <div class="wid180">
            <div class="tab">
                <ul>
                    <li id="tow1" class="on" onclick='setTab("tow",1,3)'>
                        tow1
                    </li>
                    <li id="tow2" onclick='setTab("tow",2,3)'>
                        tow2
                    </li>
                    <li id="tow3" onclick='setTab("tow",3,3)'>
                        tow3
                    </li>
                </ul>
            </div>
            <div class="tabList">
                <div id="cont_tow_1" class="one block">
                    cont_tow_1
                </div>
                <div id="cont_tow_2" class="one">
                    cont_tow_2
                </div>
                <div id="cont_tow_3" class="one">
                    cont_tow_3
                </div>
            </div>
        </div>
    </body>

</html>
直接copy别人的代码希望能帮助到你

追问



显示更多.....

就是这样 第一个DIV直接显示 我点击更多的时候在显示第二个。

温馨提示:答案为网友推荐,仅供参考
第1个回答  2014-07-14

如下代码可以实现:

<div id="divpx1">第一个DIV</div>
<div id="divpx2">第二个DIV</div>
<input type="button" value="点击显示" id="btnpx" />
<script>
window.onload = function(){
var divpx1 = document.getElementById("divpx1");
var divpx2 = document.getElementById("divpx2");
divpx2.style.display = "none";
document.getElementById("btnpx").onclick = function(){
divpx1.style.display = "none"; //加上这句在显示第二个div的同时,隐藏第一个div。不加这句两个div都显示。
divpx2.style.display = "block";
};
};
</script>

追问

那我使用按钮的时候我怎么调用这个方法呢? 我是在点击button的时候就要显示第二个,第一个还是保留。

追答<div id="divpx1">第一个DIV</div>
<div id="divpx2">第二个DIV</div>
<input type="button" value="点击显示" id="btnpx" />
<script>
window.onload = function(){
    var divpx1 = document.getElementById("divpx1"); //引号里的要和第一个div的id对应
    var divpx2 = document.getElementById("divpx2"); //引号里的要和第二个div的id对应
    divpx2.style.display = "none";
    document.getElementById("btnpx").onclick = function(){ //引号里的要和按钮的id对应
        divpx2.style.display = "block";
    };
};
</script>


上面这样就行了,调用的时候改一下div和button的id属性,js里也改一下,改成你的id就行了。

本回答被提问者采纳
第2个回答  2014-07-14
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script type="text/javascript">
function showDiv(){
document.getElementById("div2").style.display = "block";
}
</script>
</head>
<body>
<button onclick="showDiv();"> 显示</button>
<div style="width:100px;height:100px;border:1px solid red;">DIV1</div>
<div id="div2" style="width:100px;height:100px;border:1px solid blue; display:none;">DIV2</div>
</body>
</html>追问

我用的是Spring tool suite 我刚刚测试了你这个方法 但是没反应。是不是这个方法对这个软件行不通呢?

第3个回答  2014-07-14

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网