1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Document</title>
- <style>
- .box{
- position: fixed;
- top:0;
- left: 0;
- right: 0;
- bottom: 0;
- background-color: rgba(0,0,0,.5);
- }
- .box2{
- width: 200px;
- height: 200px;
- background-color: #fff;
- position: absolute;
- top: 50%;
- left: 50%;
- margin-top: -100px;
- margin-left: -100px;
- }
- </style>
- </head>
- <body>
- <div class="box">
- <div class="box2"></div>
- </div>
- <script>
- var oBox = document.getElementsByClassName("box")[0];
- var oBox2 = document.getElementsByClassName("box2")[0];
- oBox.onclick = function(){
- this.style.display = "none";
- }
- oBox2.onclick = function(e){
- this.innerText = "hello";
- // 他会阻止冒泡事件
- e.stopPropagation();
- }
-
- </script>
- </body>
- </html>
|