我使用Youtube嵌入式代码在我的网站上显示我的视频。为了显示这个视频,我使用了Jquery插件和Youtube嵌入代码。
问题我的视频无法在三星智能手机上播放或显示。
这是我的JS代码
$(document).ready(function () {
var first_child = $(".url").first().text();
$("<iframe id=videos class=" + first_child + " width=701 height=400 src='https://www.youtube.com/embed/" + first_child + "?rel=1&controls=1&showinfo=1' frameborder='0' allowfullscreen></iframe>").appendTo('#video');
$('ul#vurl li').on('click', function ()
{
var newname = $(this).children('span.url').text();
if ($('#video>iframe').hasClass(first_child)) {
$('#video').html("");
$("<iframe class=" + newname + " width=701 height=400 src='https://www.youtube.com/embed/" + newname + "?autoplay=1&rel=1&controls=1&showinfo=1' frameborder='0' allowfullscreen></iframe>").appendTo('#video');
}
if ($('#video>iframe').hasClass(newname)) {
$('#video').html("");
$("<iframe class=" + newname + " width=701 height=400 src='https://www.youtube.com/embed/" + newname + "?autoplay=1&rel=1&controls=1&showinfo=1' frameborder='0' allowfullscreen></iframe>").appendTo('#video');
} else {
$('#video').html("");
$("<iframe class=" + newname + " width=701 height=400 src='https://www.youtube.com/embed/" + newname + "?autoplay=1&rel=1&controls=1&showinfo=1' frameborder='0' allowfullscreen></iframe>").appendTo('#video');
}
}
);
});
这是用户点击我的视频后的结果HTM1
<div class="wrapper ">
<div class="bg-gray">
<div class="col-lg-9">
<div class="data" id="video"></div>
</div>
<div class="col-lg-3">
<div class="data">
<ul id="vurl">
<li class="video_title"><a class="no">title </a><span class="url" style="display: none;">T1JbM8Oged0</span></li>
<li class="video_title"><a class="no">Kham New MV </a><span class="url" style="display: none;">AfBne0tKMCw</span></li>
<li class="video_title"><a class="no">Title</a><span class="url" style="display: none;">0ynW4eg70uA</span></li>
</ul>
</div>
</div>
</div>
</div>
您正在使用一个HTML字符串作为选择器。尝试使用元素ID作为选择器,并将HTML字符串附加到其中:
$('#video').append("<iframe class=" + newname + " width=701 height=400 src='https://www.youtube.com/embed/" + newname + "?autoplay=1&rel=1&controls=1&showinfo=1' frameborder='0' allowfullscreen></iframe>");