我想使用普通的javascript检查HTML5数据属性是否存在.我已经尝试了下面的代码片段,但它不起作用.
if(object.getAttribute("data-params")==="undefined") {
//data-attribute doesn't exist
}
Run Code Online (Sandbox Code Playgroud) 我想知道如何根据url使用单个正则表达式提取youtube视频ID或播放列表ID.正则表达式还应该确保域名是youtube.com以下是我需要的一些结果:
提取播放列表ID
https://www.youtube.com/playlist?list=PLuC2HflhhpLGQ4RgqA76_Gv52fGA0909r
www.youtube.com/playlist?list=PLuC2HflhhpLGQ4RgqA76_Gv52fGA0909r
http://www.youtube.com/playlist?list=PLuC2HflhhpLGQ4RgqA76_Gv52fGA0909r
https://www.youtube.com/embed/videoseries?list=PLuC2HflhhpLGQ4RgqA76_Gv52fGA0909r
Run Code Online (Sandbox Code Playgroud)
提取视频ID
https://www.youtube.com/watch?v=fqMfRi2gJok&index=1&list=PLuC2HflhhpLGQ4RgqA76_Gv52fGA0909r
https://www.youtube.com/watch?v=fqMfRi2gJok
http://youtu.be/cCnrX1w5luM
http://youtube.com/embed/cCnrX1w5luM
http://youtube.com/v/cCnrX1w5luM
https://www.youtube.com/v/cCnrX1w5luM
www.youtube.com/v/cCnrX1w5luM
youtube.com/v/cCnrX1w5luM
Run Code Online (Sandbox Code Playgroud)
这些只是示例网址.我需要为所有可能的youtube链接结构提取相应的ID.
简而言之,提取视频ID,如果不存在,则获取播放列表ID.