使用 class 而不是 id 停止 YouTube yt-player
Stop YouTube yt-player with class instead of id
我正在根据用户的选择使用 JQuery 嵌入多个 YouTube 视频。
$('#content_frame_right').on('click', '#video_respiratory_exam', function(){
$('#content_frame_left').html("<div id='yt-player'><iframe width='380' height='285' src='https://www.youtube.com/embed/EEjIThphoig?enablejsapi=1&autoplay=1' frameborder='0' allowfullscreen></iframe></div>");
});
我需要根据对象的 class 而不是 ID 'yt-player' 停止所有视频。但是 API 要求 'yt-player' 是对象 ID:
callPlayer('yt-player', 'stopVideo');
多个对象具有相同的 ID 会导致不一致的行为。有没有办法停止所有带有 class 的视频?
尝试使用 class 检索唯一 ID,如下所示:
$(".yt-player").each(function(){
var thisPlayerID = $(this).attr("id").
callPlayer(thisPlayerID, 'stopVideo');
});
我正在根据用户的选择使用 JQuery 嵌入多个 YouTube 视频。
$('#content_frame_right').on('click', '#video_respiratory_exam', function(){
$('#content_frame_left').html("<div id='yt-player'><iframe width='380' height='285' src='https://www.youtube.com/embed/EEjIThphoig?enablejsapi=1&autoplay=1' frameborder='0' allowfullscreen></iframe></div>");
});
我需要根据对象的 class 而不是 ID 'yt-player' 停止所有视频。但是 API 要求 'yt-player' 是对象 ID:
callPlayer('yt-player', 'stopVideo');
多个对象具有相同的 ID 会导致不一致的行为。有没有办法停止所有带有 class 的视频?
尝试使用 class 检索唯一 ID,如下所示:
$(".yt-player").each(function(){
var thisPlayerID = $(this).attr("id").
callPlayer(thisPlayerID, 'stopVideo');
});