我在 W3 html 编辑器中尝试了以下代码:
主要目标:
(该代码几乎可以播放 mp4 视频,并允许用户通过单击视频屏幕来暂停/播放 - 不显示任何控件)它在 html 文件中运行良好。
我想将此代码添加到我的 WordPress 网站,但是 <script>
部分不起作用。我访问了 WordPress 帮助部分,尝试将 Javascript 合并到我的网站中。有些说明并不明显遵循。如果有人能给我一些逐步的方法来使下面的代码在 Wordpress 中工作,我将非常感激。
我使用的是 WordPress 版本 4.3.1
<!DOCTYPE html>
<html>
<body>
<! Within the WordPress text editor, there's no need for the <html> & <body> tags >
<video id="myVideo" width="320" height="176" autoplay>
<source src="http://techslides.com/demos/sample-videos/small.mp4" type="video/mp4">
Your browser does not support HTML5 video.
</video>
<script type="text/javascript">
var vid = document.getElementById("myVideo");
var isPlaying = true;
vid.onclick = function playVid() {
if (isPlaying == false){
myVideo.play();
isPlaying = true;}
else if (isPlaying == true){
myVideo.pause();
isPlaying = false; }
}
</script>
<! Within the WordPress text editor, there's no need for the <html> & <body> tags >
</body>
</html>
最佳答案
var vid = document.getElementById("myVideo");
if (isPlaying == false){
myVideo.play();
isPlaying = true;}
else if (isPlaying == true){
myVideo.pause();
isPlaying = false; }
您的变量是 vid
并且您正在使用 myVideo
调用 play()
和 pause()
是一个 ID
关于javascript - 添加脚本代码到Wordpress,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34160813/