我创建了一个在Chrome上工作正常的功能,但似乎在firefox上产生错误
ReferenceError: playNextClip is not defined
您可以在以下网址查看该网站:http://thewild.com.au/caleboys/
我的JS如下.
function queueVideos(num, amount) { if (num < amount) { document.getElementById('video-element-'+num).addEventListener( 'ended', playNextClip, false); function playNextClip() { var nextVid = num + 1; $( '#video-element-' + nextVid ).show().get(0).play(); $( '#video-element-' + num ).hide(); document.getElementById( 'video-element-' + num ).pause(); document.getElementById( 'video-element-' + num ).currentTime = 0; queueVideos(nextVid, amount) } } if (num == amount) { document.getElementById('video-element-'+num).addEventListener( 'ended', playFirst, false); function playFirst() { $( '#video-element-1' ).show().get(0).play(); $( '#video-element-' + num ).hide(); document.getElementById( 'video-element-' + num ).pause(); document.getElementById( 'video-element-' + num ).currentTime = 0; } } } queueVideos(1, 5);
为什么这在Chrome中有效但在Firefox中无效?
我该怎么做才能使它跨浏览器兼容?
谢谢!
function queueVideos(num, amount) { if (num < amount) { function playNextClip() { var nextVid = num + 1; $( '#video-element-' + nextVid ).show().get(0).play(); $( '#video-element-' + num ).hide(); document.getElementById( 'video-element-' + num ).pause(); document.getElementById( 'video-element-' + num ).currentTime = 0; queueVideos(nextVid, amount) } document.getElementById('video-element-'+num).addEventListener( 'ended', playNextClip, false); } if (num == amount) { function playFirst() { $( '#video-element-1' ).show().get(0).play(); $( '#video-element-' + num ).hide(); document.getElementById( 'video-element-' + num ).pause(); document.getElementById( 'video-element-' + num ).currentTime = 0; } document.getElementById('video-element-'+num).addEventListener( 'ended', playFirst, false); } } queueVideos(1, 5);
尝试在addeventlistener之前给出函数defination.