<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <style> *{ margin: 0; } #div1{ height: 550px; width: 100%; background: royalblue; position: fixed; z-index: 1; } #div2{ margin-left: 550px; margin-top: 150px; height: 200px; width: 300px; background: yellowgreen; position: fixed; z-index: 2; text-align: center; padding-top: 120px; } .cc{ display: none; } </style> </head> <body> <div id="div1"><p onclick="f1()">显示</p></div> <div id="div2" class="cc cctv"><p onclick="f2()">隐藏</p></div> //涉及到class等多个地方使用是,要多加几个名字 </body> <script> function f1() { var ele = document.getElementsByClassName("cctv")[0]; ele.classList.remove("cc"); //给标签添加删除属性 } function f2() { var ele = document.getElementsByClassName("cctv")[0]; ele.classList.add("cc"); } </script> </html>