我正在寻找一种方法来控制具有相同ID的同一页面上的多个iframe视频。我只是想把它们全部静音,但它只适用于第一个视频。这是我的代码!谢谢 !
<iframe id="ytplayer" type="text/html" width="100%" height="200px"
src="https://www.youtube.com/embed/bNkkFIjScY8?rel=0&showinfo=0&autoplay=1&controls=0&color=white&iv_load_policy=3&enablejsapi=1"
frameborder="0" allowfullscreen></iframe>
<iframe id="ytplayer" type="text/html" width="100%" height="200px"
src="https://www.youtube.com/embed/pKVvTKQgEH4?rel=0&showinfo=0&autoplay=1&controls=0&color=white&iv_load_policy=3&enablejsapi=1"
frameborder="0" allowfullscreen></iframe>
<script>
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
var player;
function onYouTubeIframeAPIReady() {
player = new YT.Player('ytplayer', {
events: {
'onReady': onPlayerReady
}
});
}
function onPlayerReady() {
player.playVideo();
// Mute!
player.mute();
}
</script>