【发布时间】:2018-03-06 13:53:53
【问题描述】:
我想创建一个按钮来暂停自动播放的 youtube 视频。
这是 iframe:
<iframe id="music" width="0" height="0" src="https://www.youtube.com/embed/v_FucrYWy3k?rel=1&controls=0&showinfo=0&start=1&autoplay=1&enablejsapi=1" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>
这是按钮:
<button onclick="mute()" type="button" name="button">mute</button>
这就是 JS:
function mute(){
var myVideo = document.getElementById('music');
myVideo.pauseVideo();
}
我错过了什么?
【问题讨论】:
-
你在哪里定义
iframe,你为什么要调用getElementById('music'),这是同一iframe上iframe的id?您的控制台中是否有任何错误? -
document.getElementById()... 对于初学者。 -
猜我需要使用 document.getElementById,但这也不起作用...
-
@Ionut 刚改成
document.getElementById()。还是行不通。错误:script.js:110 Uncaught TypeError: myVideo.pauseVideo is not a function at mute (script.js:110) at HTMLButtonElement.onclick (index.html:30) mute @ script.js:110 onclick @ index.html:30
标签: javascript html