2016-05-01 3 views
-1

のHTML部分では、コードに関連するイベントは、スクリプトタグマウスイベント、私はコードに関連するイベントを含めたくないいただきました!間違って私のコード

<!doctype html> 
 
    <head> 
 
    <style> 
 
     div{ 
 
      width:200px; 
 
      background-color:grey; 
 
     } 
 
    </style> 
 

 
    <body> 
 
     <p>use the below area for events</p> 
 
     <div> point here </div> 
 
     <a id="event_output"></a> 
 

 
     <script> 
 
     var output=document.getElementById("event_output").innerHTML; 
 
     var div=document.getElementsByTagName("div"); 
 

 
     div[0].onmouseover=function(){output="mouse over"} 
 
     div[0].onmouseout=function(){output="mouse out"} 
 

 
     </script>     
 
      
 

 
    </body>

答えて

1

内でなければなりません文字列である変数outputを更新するだけです。代わりに、オブジェクト参照を格納し、そのinnerHTMLプロパティを設定します。

<style> 
 
    div { 
 
    width: 200px; 
 
    background-color: grey; 
 
    } 
 
</style> 
 

 
<p>use the below area for events</p> 
 
<div>point here</div> 
 
<a id="event_output"></a> 
 

 

 
<script> 
 
    var output = document.getElementById("event_output"); 
 
    var div = document.getElementsByTagName("div"); 
 

 
    div[0].onmouseover = function() { 
 
    output.innerHTML = "mouse over" 
 
    } 
 
    div[0].onmouseout = function() { 
 
    output.innerHTML = "mouse out" 
 
    } 
 
</script>

関連する問題