通过onclick单击事件,实现效果,代码如下:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>开关按钮设置</title> </head> <link rel="stylesheet" href="css/Default style sheet.css" /> <style> div{ width:120px; margin: 0px auto; border: 2px solid black;} ul{ display: none; } </style> <script> window.onload=function(){ var odiv=document.getElementById("v"); var oli=odiv.getElementsByTagName("ul")[0]; var onf=true odiv.onclick=function(){ if (onf==true) { oli.style.display=‘block‘; onf=false } else{ oli.style.display=‘none‘; onf=true } } } </script> <body> <div id="v"> <h4>你好啊,小老弟</h2> <ul> <li>come</li> <li>on</li> <li>do</li> </ul> </div> </body> </html>
实现效果:
原文地址:https://www.cnblogs.com/web928943/p/9999813.html
时间: 2024-10-05 11:14:58