使用display属性操作元素

时间:2015-06-11 17:17:13

标签: javascript jquery html css

<!DOCTYPE html>
<html>

<head>
    <style>
        #myDIV {
            width: 500px;
            height: 500px;
            background-color: lightblue;
            display: none;
        }

        #second {
            width: 500px;
            height: 500px;
            background-color: lightblue;
            display: none;
        }
    </style>
</head>

<body>

    <button onclick="myFunction()">Try it</button>
    <button onclick="myFunction2()">Try this now</button>
    <div id="myDIV">
        This is my DIV element.
    </div>
    <div id="second">
        This is my DIV2 element.
    </div>

    <script>
        function myFunction() {
            document.getElementById("myDIV").style.display = "block";
        }
    </script>

    <script>
        function myFunction2() {
            document.getElementById("second").style.display = "block";
        }
    </script>
</body>

</html>

所以我有这个代码会在点击按钮时显示div元素。但是我想要一次点击&#34; second&#34;按钮,我想要&#34; myDiv&#34;消失,&#34;秒&#34;取而代之(确切位置),反之亦然。

请帮忙吗?

1 个答案:

答案 0 :(得分:2)

/**
 * @SWG\Api(
 * path="/building/{buildingId}",
 * @SWG\Operation(
 * method="GET",
 * type="Building",
 * summary="Returns a Building object by ID",
 * nickname="building/getBuilding",
 * @SWG\Parameter(
 * name="buildingId",
 * description="ID of the building that needs to be fetched",
 * paramType="path",
 * required=false,
 * type="string",
 * defaultValue="1"
 * )
 * )
 * )
 */