我通过使用 href 值将 youtube 视频嵌入并附加到 div 并将其添加到 youtube.com/embed/ +hrefvariable。我只需要一些指导来检查 youtube 视频是否已经在 div 中,而不是运行将其附加到那里的点击功能。我正在考虑将 .length() 与父 div 一起使用?
这是附加功能:
$(function () {
$(".youtube").click(function (a) {
a.preventDefault();
a = '<iframe src="http://www.youtube.com/embed/' + $(this).attr("href") + '?&iv_load_policy=3&autoplay=1#t=0m12s&rel=0" frameborder="0" allowfullscreen ></iframe>';
$("#currentvid").html(a);
$("#currentvid").animate({
opacity: 1
}, 1E3);
return !1
})
});