【发布时间】:2013-09-30 10:02:23
【问题描述】:
为什么在我的简单 JQuery 代码中没有绑定事件? - http://pastebin.com/24J6q5G0
相关部分:
<div class="videoWrapper">
<video controls preload autoplay>
<source src="http://techslides.com/demos/sample-videos/small.mp4" type="video/mp4">
<source src="http://techslides.com/demos/sample-videos/small.ogv" type="video/ogg">
</video>
</div>
<div class="videoWrapper">
<video controls preload="none">
<source src="http://techslides.com/demos/sample-videos/small.mp4" type="video/mp4">
<source src="http://techslides.com/demos/sample-videos/small.ogv" type="video/ogg">
</video>
</div>
还有 javascript:
$(document).ready(function() {
var vid0 = $(document.getElementsByClassName('videoWrapper')[0]);
var vid1 = $(document.getElementsByClassName('videoWrapper')[1]);
vid1.hide();
vid0.bind('ended', function() {
vid1.show();
})
})
【问题讨论】:
-
该事件需要在
source标签而不是video标签上完成,因此将其更改为:vid0.children().bind('ended', function() {有效。
标签: javascript jquery events html5-video jquery-events