我正在使用 jQuery for/with javascript 来尝试修改 .htm 文件中 div 的内部 HTML 代码。我正在使用此处推荐的 jQuery DOM 就绪事件(http://stackoverflow.com/questions/9856140/javascript-uncaught-typeerror-cannot-call-method-addeventlistener-of-null)以避免脚本在 div 准备好之前运行,但这没关系;我不断收到这个错误。
我必须说距离我接触 Javascript 仅几天时间,距离我上次使用 HTML 已经有很长时间了,所以请不要丢弃任何典型的菜鸟错误,因为很可能就是这样。
这是我正在使用的文件,托管在 Skydrive 中:
可以猜到,我使用 videoJS 作为视频播放器。videojs 的 CSS 和 JS 文件可以在线 (http://videojs.com/#section5) 或离线引用,如 AMPlayer.htm 所示,但这只是间接信息,因为它看起来更像是一个问题javascript而不是videojs的问题。
编辑:我认为是文件的重要部分:
AMPlayer.htm(我认为问题出在这里,所以我粘贴了整个文件):
<!DOCTYPE html>
<html>
<head>
<link href="video-js.css" rel="stylesheet" type="text/css">
<script src="video-js.js"></script>
<script src="jquery-1.7.2.min.js"></script>
<script src="playlister.js" type="text/javascript"></script>
<title>AMPlayer</title>
</head>
<body>
<div id="the-video" class="video-js-box">
<span> </span>
</div>
</body>
</html>
播放列表.js:
function postVideo()
{
getNextVideo();
document.write("NEXT VIDEO: "+videoNames[iNewVideoId]+"<br>");
var video1 = '<video id="AMPlayer" class="video-js vjs-default-skin" preload="auto" width="650" height="365" data-setup="{}" autoplay> <source src="videos/AVANCE/vid.mp4" type="video/mp4" /><source src="videos/AVANCE/vid.webm" type="video/webm" /></video>';
//document.write(video1); This writes the text so the video is played, but it drives me to an undesired behaviour
document.write("BEFORE THE .SETUP<br>");
//$("#the-video").html(video1); This doesn't work
//document.getElementById("the-video").innerHTML=video1; This does neither work
//window.VideoJS.setup($'video1'));
document.write("AFTER THE .SETUP<br>");
document.getElementById("AMPlayer").addEventListener('ended', postVideo, true);
//$(".video-js")[0].player.play();
document.write("AFTER THE .PLAY<br>");
//postVideo();
}
任何提供的帮助肯定会非常有用。提前致谢。