Javascript 如何获取youtube嵌入的id?
我需要获取youtube内容的id,到目前为止,我可以通过以下URL实现:Javascript 如何获取youtube嵌入的id?,javascript,jquery,Javascript,Jquery,我需要获取youtube内容的id,到目前为止,我可以通过以下URL实现: var obtenerUrlId = function(url){ var regExp = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#\&\?]*).*/; var match = url.match(regExp); return (match&&match[7].length=
var obtenerUrlId = function(url){
var regExp = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#\&\?]*).*/;
var match = url.match(regExp);
return (match&&match[7].length==11)? match[7] : false;
}
您可以使用此截图从url获取youtubeId
var splited = recipes.video.split('/');
var lastPart = splited[splited.length - 1];
var id = lastPart.split('watch?v=');
var youtubeId = id[id.length - 1];
可能重复的