Javascript 如何在页面加载时将YouTube视频URL动态转换为iframe嵌入代码?
我正在使用它将youtube url转换为嵌入url。我是jquery新手,请在代码方面给我建议Javascript 如何在页面加载时将YouTube视频URL动态转换为iframe嵌入代码?,javascript,jquery,html,spring-mvc,Javascript,Jquery,Html,Spring Mvc,我正在使用它将youtube url转换为嵌入url。我是jquery新手,请在代码方面给我建议 function vidgallerylist() { var url=path+"/customer/video"; var value = $(this).attr(result.data[i].vidgalleryUrl); value = value.replace('feature=player_embedded&','
function vidgallerylist()
{
var url=path+"/customer/video";
var value = $(this).attr(result.data[i].vidgalleryUrl);
value = value.replace('feature=player_embedded&','');
if (value.match('(http(s)?://)?(www.)?youtube|youtu\.be'))
{
if (value.match('embed')) { youtube_id = value.split(/embed\//)[1].split('"')[0]; }
else { youtube_id = value.split(/v\/|v=|youtu\.be\//)[1].split(/[?&]/)[0]; }
value = "http://www.youtube.com/v/"+youtube_id;
var htmlInput = "<object width=\"640\" height=\"390\"><param name=\"movie\" value=\""+value+"\"></param><param name=\"allowScriptAccess\" value=\"always\"></param><embed src=\""+value+"\" type=\"application/x-shockwave-flash\" allowscriptaccess=\"always\" width=\"640\" height=\"390\"></embed></object>";
$(this).after("<p>"+htmlInput+"</p>");
}
$.ajax({
type: "GET",
url: url,
success: function(result) {
console.log(result);
for(var i=0;i<result.data.length;i++)
{
$("#tablevidgalleryid").append("<tr><td><a href='"+result.data[i].vidgalleryUrl+"'>"+value+"</a></td></tr>");
}
$('#tablevidgalleryid').DataTable();
}
});
}
函数vidgallerylist()
{
var url=path+“/customer/video”;
var value=$(this.attr(result.data[i].vidgalleryUrl);
value=value.replace('feature=player\u embedded&','');
if(value.match('(http(s)?:/)?(www.)?youtube | youtu\.be'))
{
if(value.match('embed'){youtube_id=value.split(/embed\/)[1].split('“')[0];}
else{youtube_id=value.split(/v\/| v=|youtu\.be\/)[1]。split(/[?&]/)[0];}
值=”http://www.youtube.com/v/“+youtube_id;
var htmlInput=“”;
$(此)。在(“”+htmlInput+“”)之后;
}
$.ajax({
键入:“获取”,
url:url,
成功:功能(结果){
控制台日志(结果);
对于(var i=0;iCan您是否可以附上您正在获得的正确错误日志/控制台输出?@Ajinkya:)你好,兄弟,我有MySQL(DB)中的YouTube URL链接列表,我想在html页面中动态获取要加载和运行(播放)的视频列表。