2011-01-20 57 views

回答

0

打開控制檯,你會看到:

Uncaught TypeError: Cannot read property 'MouseX' of undefined

看來,在line 33在你的JavaScript代碼,document.Showundefined

document.Show.MouseX.value = tempX; 

當你click,你會得到這樣的:

Uncaught TypeError: Cannot read property 'style' of null

各地line 52其中marknull

<div id="map" onclick=" 

mark.style.left = tempX + 'px'; 
mark.style.top = tempY + 'px'; 

"> 
    <div id="mark"></div> 

您可以向下移動整個<script>標籤朝下方,放置它只是在關閉</body>標籤內,以便您的document.getElementById('mark');會找到這個元素。

像這樣:

<body> 
    <div id="map" onclick=" 

    mark.style.left = tempX + 'px'; 
    mark.style.top = tempY + 'px'; 

    "> 
     <div id="mark"></div>    
    </div> 
    <script type="text/javascript"> 
    <!-- 
     var IE = document.all?true:false; 
     if (!IE) document.captureEvents(Event.MOUSEMOVE) 
     document.onmousemove = getMouseXY; 

     var mark = document.getElementById('mark'); 

     var tempX = 0; 
     var tempY = 0; 
     function getMouseXY(e) { 
      if (IE) { // grab the x-y pos.s if browser is IE 
       tempX = event.clientX + document.body.scrollLeft; 
       tempY = event.clientY + document.body.scrollTop; 
      } 
      else { // grab the x-y pos.s if browser is NS 
       tempX = e.pageX; 
       tempY = e.pageY; 
      } 
      if (tempX < 0){tempX = 0;} 
      if (tempY < 0){tempY = 0;} 

      document.Show.MouseX.value = tempX; 
      document.Show.MouseY.value = tempY; 
      return true; 
     } 
    //--> 
    </script> 
</body> 
+0

如何在Firefox中打開控制檯?另外,我該如何解決這些問題?我是JS的初學者。 – CyanPrime 2011-01-20 23:32:24