我们如何更改 YouTube URL(链接)列表:https://www.youtube.com/watch?v= .... 至 https://www.youtube.com/embed?v= .... 动态地在 Jquery 中,我是 html 和 jquery 的新手,请在代码中给我建议。
我的js页面:
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();
}
});
}
html 页面:
<h2>List of Video Gallery</h2>
<table class="table " id="tablevidgalleryid">
<thead>
<tr>
<th>Title</th>
<th>Videos url</th>
</tr>
</thead>
<tbody id="vidlistshow">
</tbody>
</table>
</div>
在我的浏览器页面中如下所示:
最佳答案
试试这个
<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>
关于javascript - 使用 Jquery 将 YouTube 链接从观看更改为动态嵌入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60034778/