2017-11-29 4 views
0

私は学校のための仕事があるので、何回オーディオが再生されたかを示すゲームをする必要があります。私は本当に私は、インターネットからこのコードを試してみましたが、私はビデオと試みたが、それは何回再生するかを数える--JavascriptまたはJquery

"Cannot set property 'innerHTML' of null" `

var iterations = 1; 
 

 
document.getElementById('iteration').innerText = iterations; 
 

 
myVideo.addEventListener('ended', function() { 
 

 
    if (iterations < 5) { 
 
    this.currentTime = 0; 
 
    this.play(); 
 
    iterations++; 
 
    document.getElementById('iteration').innerText = iterations; 
 
    } 
 
}, false);
<video width="320" height="240" id="myVideo" controls> 
 
    <source src="http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4" type="video/mp4" /> 
 
    <source src="http://clips.vorwaerts-gmbh.de/big_buck_bunny.ogv" type="video/ogg" /> 
 
Your browser does not support the video tag. 
 
</video>

+0

私は '.innerHTML'を見ることができません。 –

+1

コードが現在の反復を表示しようとしています。これをHTMLに追加してください: '

反復:

'。 –

+0

大変申し訳ありませんが、私の間違いはinnertext –

答えて

1

言うと更新する要素がありませんでした、それを行う方法がわかりません変数の反復

は、DOMの「反復」要素の作成後に確認してくださいJavaScriptの火災を作るか、エラー

0123を取得しますあなたのコードで

// set iteration to 1 
 
var iterations = 1; 
 

 
document.getElementById('iteration').innerText = iterations; 
 
      
 
     myVideo.addEventListener('ended', function() { 
 

 
     if (iterations < 5) { 
 

 
      this.currentTime = 0; 
 
      this.play(); 
 
      iterations ++; 
 

 
      document.getElementById('iteration').innerText = iterations; 
 

 
     } 
 

 
}, false);
<video width="320" height="240" id="myVideo" controls> 
 
     <source src="http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4" type="video/mp4" /> 
 
     <source src="http://clips.vorwaerts-gmbh.de/big_buck_bunny.ogv" type="video/ogg" /> 
 
     Your browser does not support the video tag. 
 
    </video> 
 
<p>Iteration: <span id="iteration"></span></p>

+0

私はそれを使用しましたが、それでもまだUncaught TypeError:nullのプロパティ 'innerText'を設定できません なぜ私はわかりません –

+0

私のコンピュータではない –

+0

JavaScriptをどこに追加しましたか? –

関連する問題