Javascript 单击更改JWPlayer视频
我读了这篇文章并尝试了一下,但是我在播放第二段视频时遇到了问题。每当我点击Play Video 2时,什么都不会发生!代码如下Javascript 单击更改JWPlayer视频,javascript,onclick,jwplayer,Javascript,Onclick,Jwplayer,我读了这篇文章并尝试了一下,但是我在播放第二段视频时遇到了问题。每当我点击Play Video 2时,什么都不会发生!代码如下 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>My JWPlayer</title>
<script type="text/javascript" src="jwplayer.js" ></script>
<script type="text/javascript">
function changeVideo(filename) {
jwplayer("video").setup({
file: filename,",
height: 360,
width: 640,
});
jwplayer('video').load();
}
</script>
</head>
<body>
<div id="video">Loading the player ...</div>
<script type="text/javascript">
jwplayer("video").setup({
file: "http://longtailvideo.com/jw/upload/bunny.flv",
height: 360,
width: 640
});
</script>
<p><a href="javascript:void();" onclick="javascript:changeVideo("http://www.auby.no/files/video_tests/h264_720p_mp_3.1_3mbps_aac_shrinkage.mp4");">Play Video 2</a></p>
</body>
</html>
html
要使其更有趣,请将videoURL作为数据属性添加到锚点
<div id="video">Loading the player ...</div>
<a href="#" class="changeVideo" data-video_url="videoURL2">load video 2</a>
这就是您所需要的将onclick属性更改为:onclick=javascript:changeVideo'urlString';此外,如果可能,请设置链接?changeVideo函数定义中存在语法错误。删除宽度:640后的逗号。和“file:filename,,”应该是file:filename,仍然不走运,这里有一个链接:
<div id="video">Loading the player ...</div>
<a href="#" class="changeVideo" data-video_url="videoURL2">load video 2</a>