Javascript 使用Jquery将YouTube链接从watch更改为动态嵌入
如何在Jquery中动态地将YouTube URL(链接)列表从…更改为…,我是Jquery的html新手,请在代码中给我建议 我的js页面:Javascript 使用Jquery将YouTube链接从watch更改为动态嵌入,javascript,java,jquery,html,Javascript,Java,Jquery,Html,如何在Jquery中动态地将YouTube URL(链接)列表从…更改为…,我是Jquery的html新手,请在代码中给我建议 我的js页面: function vidgallerylist(){ var url=path+"/customer/video"; $.ajax({ type: "GET", url: url, success: function(result) { console.log(re
function vidgallerylist(){
var url=path+"/customer/video";
$.ajax({
type: "GET",
url: url,
success: function(result) {
console.log(result);
for(var i=0;i<result.data.length;i++){
$('#vidlistshow').html(function(i,url){
var url = result.data[i].vidgalleryUrl;
var id = url.split('watch?v=')[2];
$("#tablevidgalleryid").append('<tr><td>'+result.data[i].vidgalleryTitle+'</td><td><iframe width="380" height="258" src="http://www.youtube.com/embed/' + id + '" frameborder="0" allowfullscreen></iframe></td></tr>');
});
}
$('#tablevidgalleryid').DataTable();
}
});
}
函数vidgallerylist(){
var url=path+“/customer/video”;
$.ajax({
键入:“获取”,
url:url,
成功:功能(结果){
控制台日志(结果);
对于(var i=0;i试试这个
<script>
$(document).ready(function(){
var songsUrl = ["https://www.youtube.com/watch?v=BdRmjO04kH8", "https://www.youtube.com/watch?v=y7P9UWpHpMs", "https://www.youtube.com/watch?v=ES0oYC0hyD8"];
$.each(songsUrl, function(index, value){
var splitLink = value.split('watch?v=')
var embedLink1 = splitLink.join("embed/")
$("#result").append(index + ": " + embedLink1 + '<br>');
});
});
</script>
<body>
<div id="result"></div>
</body>
$(文档).ready(函数(){
var songsUrl=[”https://www.youtube.com/watch?v=BdRmjO04kH8", "https://www.youtube.com/watch?v=y7P9UWpHpMs", "https://www.youtube.com/watch?v=ES0oYC0hyD8"];
$.each(songsUrl,函数(索引,值){
var splitLink=value.split('watch?v='))
var embedLink1=splitLink.join(“嵌入/”)
$(“#结果”).append(index+”:“+embedLink1+”
);
});
});
你好,zabih ullah,感谢您的快速回复。但是,我的数据库中有多个Url链接。请以html动态显示page@Rakesh,只是一个随机的想法,如果你将我的代码插入for循环,可能会解决你的问题。是的,兄弟,我添加了你的代码。但是,出现了视频未播放错误。请稍后再试(播放ID:m8nwvnpdl-SSpn2)了解更多我的代码不是在播放视频。我只是将url
转换为embedUrl
,并在控制台上显示它。您可以在控制台上检查,如果您得到所需的结果,那么您可以使用它。我已经在@Rakesh编辑了我的答案,我想现在它会给出您想要的结果
<script>
$(document).ready(function(){
var songsUrl = ["https://www.youtube.com/watch?v=BdRmjO04kH8", "https://www.youtube.com/watch?v=y7P9UWpHpMs", "https://www.youtube.com/watch?v=ES0oYC0hyD8"];
$.each(songsUrl, function(index, value){
var splitLink = value.split('watch?v=')
var embedLink1 = splitLink.join("embed/")
$("#result").append(index + ": " + embedLink1 + '<br>');
});
});
</script>
<body>
<div id="result"></div>
</body>