admin管理员组文章数量:1336681
Just need a little push as I have this almost working.
I want to feed jquery a URL and have it strip everthing but the video url.
Here is my code:
var url = '';
$results = url.match("[\\?&]v=([^&#]*)");
alert($results);
});
I'm getting this as an output -
?v=bxp8NWvIeSo,bxp8NWvIeSo
When I only want
bxp8NWvIeSo
Just need a little push as I have this almost working.
I want to feed jquery a URL and have it strip everthing but the video url.
Here is my code:
var url = 'http://www.youtube./watch?v=bxp8NWvIeSo';
$results = url.match("[\\?&]v=([^&#]*)");
alert($results);
});
I'm getting this as an output -
?v=bxp8NWvIeSo,bxp8NWvIeSo
When I only want
bxp8NWvIeSo
Share Improve this question asked Jan 29, 2010 at 18:05 wesboswesbos 26.3k31 gold badges108 silver badges144 bronze badges 1- It's giving u a list of items, an easy way to do that is only fetching everything after the '=' – fmsf Commented Jan 29, 2010 at 18:07
2 Answers
Reset to default 6if you are not forced to use match, you can use "split":
var getList = function(url, gkey){
var returned = null;
if (url.indexOf("?") != -1){
var list = url.split("?")[1].split("&"),
gets = [];
for (var ind in list){
var kv = list[ind].split("=");
if (kv.length>0)
gets[kv[0]] = kv[1];
}
returned = gets;
if (typeof gkey != "undefined")
if (typeof gets[gkey] != "undefined")
returned = gets[gkey];
}
return returned;
};
var url = 'http://www.youtube./watch?v=bxp8NWvIeSo';
$result = getList(url, "v");
alert($result);
First, remove the $ in front of results... I assume that was a typo. Next, replace
$results = url.match("[\\?&]v=([^&#]*)");
with
results = url.match("[\?&]v=([^&#]*)")[1];
match() will return an array if there is a successful match. You're currently getting the entire array. What you want is the second element of the array (match()[1]
) which is what is inside your capturing parentheses.
本文标签: javascriptGrab the youtube Video ID with Jquery amp match()Stack Overflow
版权声明:本文标题:javascript - Grab the youtube Video ID with Jquery & .match() - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742332446a2454965.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论