通常我们在做开发的时候需要通过单击切换对立事件,简单做了一个模型。
<!DOCTYPE html> <html> <head> <title>javascript</title> <meta charset="utf-8"> <style type="text/css"> #box{ height: 200px; line-height: 200px; text-align: center; background: #eeeeee; } </style> </head> <body> <div id="box"> 单击鼠标显示边框 </div> <script type="text/javascript"> var box = document.getElementById('box'); var flog = true; box.onclick = function(){ if(flog){ box.style.border = "3px solid #000000"; box.innerHTML = "单击鼠标隐藏边框"; flog = false; }else{ box.style.border = "0px"; box.innerHTML = "单击鼠标显示边框" flog = true; } } </script> </body> </html>