2017-11-06 12 views
1

コード:HTML内のビデオプレーヤーの仕事が、表示されませポスターイメージhtmlタグのdocument.writeに変数スクリプトを作成する方法は?

<script>var posterimage=/images/videos/intro/iamge01.png;</script> 
<script>document.write('<video controls="controls" height="300" id="video-playlist" poster="VARIABLE" preload="none" src="video.mp4" width="300"></video>');</script> 

+0

はposterimageの値を引用符で囲む入れてみてください。イメージがアクセス可能であることを確認してください(http://yourdomain.com/images/videos/intro/iamge01.png、ファイル名の綴りを確認してください(iamge01?) – dwilliss

答えて

0

あなたがこれを行うには、文字列concatenationを使用する必要があります。

var posterimage= '/images/videos/intro/iamge01.png'; 
document.write('<video controls="controls" height="300" id="video-playlist" poster="' + posterimage +'" preload="none" src="video.mp4" width="300"></video>'); 

あなたもこれを行うにはtemplate literalsを使用することができます。

var posterimage= '/images/videos/intro/iamge01.png'; 
document.write(`<video controls="controls" height="300" id="video-playlist" poster="${posterimage}" preload="none" src="video.mp4" width="300"></video>`); 
0
  • まず、あなたがする各スクリプトの命令を必要としませんそれ自身で scriptタグである。
  • 新しいコンテンツをwindowに作成していない限り、document.write()を使用しないでください。代わりに、既存の要素 を入力してください。
  • 第3に、リテラル文字列を引用符で囲む必要があります。
  • 最後に、あなただけの あなたの文字列に変数の参照を連結する必要があります。

    <script> 
        // String literals must be quoted 
        var posterimage = "/images/videos/intro/iamge01.png"; 
    
        // You should get a reference to an empty container element 
        // that you want the video to go into and then just set the 
        // content of that element: 
        elementReference.innerHTML(`<video controls="controls" height="300" 
                id="video-playlist" poster="` + 
                posterimage + `" preload="none" 
                src="video.mp4" width="300"></video>`); 
    </script> 
    
関連する問題