企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
效果图 ![](https://box.kancloud.cn/e3e3c0408c15ef1d925d66ca6fada876_239x220.gif) 语法内容 > parent.classList.toggle("none");! 代码内容 ``` <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> <style> #parent{ width:100px; height: 100px; background: red; } .none{ display: none; } /* .show{ display: block; } */ </style> </head> <body> <div id="parent" class="none"> </div> <button id="toggle">toggle</button> <script> var toggle = document.getElementById("toggle"); var parent = document.getElementById("parent"); toggle.onclick = ()=>{ // if(parent.className == "none"){ // parent.className = "show" // } // else{ // parent.className = "none" // }当前注释段同下一句效果一致 parent.classList.toggle("none"); //执行toggle的class只能有一个 } </script> </body> </html> ```