我在主视频容器下方有一些缩略图。
我会喜欢当您单击每个缩略图时 - 相关视频加载并开始播放
使用新的 YOUTUBE API IFRAME 方法此处
您的帮助或指导将是感谢
JSFIDDLE 预览这里
预览链接已更新***
I have some thumbnails below the main video container.
I will like when you click on each thumbnail - the associated video loads and start playing
Using the NEW YOUTUBE API IFRAME approach here
Your help or direction will be appreciated
PREVIEW ON JSFIDDLE HERE
PREVIEW LINK UPDATED***
发布评论
评论(1)
请参阅此小提琴: http://jsfiddle.net/Y9j7R/5/
在加载时运行此代码:
代码详细解释
(锚点)元素,
for
。在每次迭代期间,通过a[i]
引用“当前”锚点。!
) 包含“#ytplayer
” href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/RegExp/test" rel="nofollow noreferrer">测试
方法<强>正则表达式。如果此条件成立(即:href
属性不包含“#ytplayer
”),continue
语句终止当前迭代,并跳转到下一个锚点。innerHTML
请求当前锚点的属性。匹配
方法用于获取视频id。 正则表达式/\/vi\/([^\ /]+)/
表示:匹配等于/vi/<任何连续的非斜杠字符>
的子字符串,并且分组<任何连续的非斜杠字符>
.当找到这样的子字符串时,
link
变量就有一个属性1
(一),它保存该组的值。否则,link
等于null
。link
变量不为null
,则为匿名function
被创建(第 5-9 行)并执行(第 9 行)。函数的第一个参数将通过vidId
(变量)引用。函数
到当前锚点的onclick
属性。将函数分配给onclick
属性将导致 要定义的onclick
事件处理程序。loadVideoById
<player
对象的 /strong> 方法(由 YouTube javascript API)。link[1]
作为第一个参数传递。参考文献
for
循环和继续
语句函数
测试
<RegExp
对象的 /strong> 方法match
函数与正则表达式结合使用innerHTML
元素的属性onclick
事件处理程序另一个有趣的答案
See this fiddle: http://jsfiddle.net/Y9j7R/5/
Run this code on load:
Detailed explanation of the code
<a>
(anchor) elements in the documentfor
. During each iteration, the "current" anchor is referred througha[i]
.href
attribute does not (!
) contain "#ytplayer
" using thetest
method of the Regular Expression. If this condition is true (ie: thehref
attribute does not contain "#ytplayer
"), thecontinue
statement terminates the current iteration, and jumps to the next anchor.innerHTML
property of the current anchor is requested. Thematch
method is used to get the video id. The Regular expression/\/vi\/([^\/]+)/
means: match a substring which equals/vi/<any consecutive non-slash chars>
, and group<any consecutive non-slash chars>
.When such a substring is found, the
link
variable has a property1
(one), which holds the value of this group. Otherwise,link
equalsnull
.link
variable is notnull
, an anonymousfunction
is created (lines 5-9) and executed (line 9). The first argument of the function will be referenced throughvidId
(variable).function
to theonclick
property of the current anchor. Assigning a function to theonclick
property will cause theonclick
event handler to be defined.loadVideoById
method of theplayer
object (as defined by the YouTube javascript API).link[1]
as a first parameter.References
for
loops and thecontinue
statementfunctions
in JavaScripttest
method of theRegExp
objectmatch
function in conjunction with a Regular expressioninnerHTML
property of an elementonclick
event handlerloadVideoById
method of the YouTube JavaScript APIAnother interesting answer