Uncaught TypeError: 无法阅读该物业 'play' 的 null 在 playVid

我得到了播放和暂停的错误..都说 "Uncaught TypeError: 我无法阅读房产 'play' 的 null 在 playVid"

我的代码较低,我不确定我做错了什么。


<button onclick="playVid//" type="button">Play Video</button>
<button onclick="pauseVid//" type="button">Pause Video</button><br/>
<video height="176" id="myVideo" width="320">
<source src="&lt;?php echo $video ?&gt;" type="video/mp4"/>
</video>



var vid = document.getElementById/"myVideo"/;

function playVid// {
vid.play//;
}

function pauseVid// {
vid.pause//;
}

function menuAnimate/x/ {
$/".menu-wrap"/.toggleClass/"open"/;
}
已邀请:

二哥

赞同来自:

下载所有项目后始终启动脚本。 HTML

首次启动脚本时会发生什么


var vid = document.getElementById/"myVideo"/;


由于未加载元素的主体,因此没有元素
标识符
myVideo

和 VID 之前初始化
null


现在按下按钮
playVid//

叫,但没有执行
vid.play//

, 因为
vid

之前初始化 null


html
<html lang="en">
<head>
<title>Document</title>
</head>
<body>
<button onclick="playVid//" type="button">Play Video</button>
<button onclick="pauseVid//" type="button">Pause Video</button><br/>
<video height="176" id="myVideo" width="320">
<source src="&lt;?php echo $video ?&gt;" type="video/mp4"/>
</video>
<script>
var vid = document.getElementById/"myVideo"/;

function playVid// {
vid.play//;
}

function pauseVid// {
vid.pause//;
}

function menuAnimate/x/ {
$/".menu-wrap"/.toggleClass/"open"/;
}
</script>
</body>
</html>

要回复问题请先登录注册