Home  >  Article  >  Web Front-end  >  JS实现从连接中获取youtube的key实例

JS实现从连接中获取youtube的key实例

WBOY
WBOYOriginal
2016-06-01 09:54:341295browse

本文实例讲述了JS从连接中获取youtube的key的方法。分享给大家供大家参考。具体分析如下:

这段代码演示了从字符串中截取子字符串的方法

<code class="language-javascript">// Example link:
// <a id="myLink" href="http://www.youtube.com/watch?v=cyRqR56aCKc&feature=PlayList&p=00000000000&index=0&playnext=1">Youtube link</a>
var youtubeLink = document.getElementById('myLink').href;
var youtubeVideoKey = youtubeLink.substr(youtubeLink.lastIndexOf("v=") + 2, 11);
// youtubeVideoKey will return "cyRqR56aCKc"
</code>

希望本文所述对大家的javascript程序设计有所帮助。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn