代码:
<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>
视频播放器在html中工作,但海报图片没有出现。
答案 0 :(得分: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>`);
答案 1 :(得分:0)
script
标记。document.write()
在新的window
中创建新内容。相反,只需填充一个
预先存在的元素。最后,您只需要将变量引用连接到 你的字符串:
<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>