三目运算符
<html> <head> <meta charset="utf-8"> <title>无标题文档</title> <style type="text/css"> #div1 { width: 100px; height:100px; background: red; display: none; } </style> </head> <body> <script> function showhide() { var odiv=document.getElementById('div1'); odiv.style.display=='block'?odiv.style.display='none':odiv.style.display='block'; } </script> <input type="button" value="显示隐藏" onClick="showhide()" /> <div id="div1"> </div> </body> </html>
欢迎访问每天进步网:https://meitianjinbu.cn/