addEventListener mousemove后,addEventListener单击无法正常工作

时间:2015-12-30 21:15:23

标签: javascript javascript-events event-handling

点击事件不起作用只有鼠标移动,即使它工作她。鼠标单击文档时,mouseclick变量保持为0不会增加。无法理解发生了什么。

<style type="text/css">
 #besoeasy 
 {
     height:auto;
     width:auto;
     position:absolute;
     top:50;
     left:50;
     border-bottom:1px #76e042 solid;
     border-bottom:0px blue solid;
     color:#ffffff;
     padding:0px;
     z-index:1001;
     font-size:13px;}
     </style>
         <div id="besoeasy">
                 <a href="#" onclick="getValue()" target="_blank"> 
                       this is the best thing you have : 
                </a>
          </div>
    <script type="text/javascript">
               var mouseclick=0;
               window.onload = function() { 
                  if(mouseclick==0)   {document.getElementById("besoeasy").style.display = 'block';}
                   else{document.getElementById("besoeasy").style.display = 'none';}
            };
           var div = document.getElementById('besoeasy');
                 document.addEventListener('mousemove',function(e) {   
                 div.style.left = e.pageX -160+"px";
                 div.style.top = e.pageY -60+"px";
            });

              document.addEventListener('click',function(e) {   
                     if(mouseclick==0){
                      mouseclick++; 
                      }else{
                         document.getElementById("besoeasy").style.display = 'none';
         }
         });

 </script>

0 个答案:

没有答案