我正在使用 YouTube Iframe,如下所示。我想让我的播放器在 API 加载后立即加载。
我创建了一个系统,让我网站的用户可以选择将哪些视频加载到播放列表中,因此我无法对 YouTube 视频 ID 进行硬编码。是否可以创建一个 onclick 函数来触发加载播放器的事件?如果是,怎么办??
非常感谢!!!
<script>
// 2. This code loads the IFrame Player API code asynchronously.
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
// 3. This function creates an <iframe> (and YouTube player)
// after the API code downloads.
var player;
function onYouTubeIframeAPIReady() {
player = new YT.Player('player', {
height: '390',
width: '640',
videoId: 'M7lc1UVf-VE',
events: { //CAN I REPLACE THE ONREADY EVENT WITH ONE …Run Code Online (Sandbox Code Playgroud)