[英]HTML5 video: Uncaught TypeError: Cannot read property '0' of undefined
[英]HTML5 video Uncaught TypeError: .play is not a function
我在單擊 buttonc 后視頻自動播放有問題,這會打開要播放視頻的基礎模式。 當我點擊按鈕打開帶有視頻的模式時,它會打開但視頻沒有開始播放。
在控制台中,我得到 Uncaught TypeError: .play is not a function error
打開模態按鈕:
<div data-open="movieModal" id="movieModalOpenMedium">Open</div>
視頻模態:
<div class="reveal full" id="movieModal" data-reveal data-reset-on-close="true">
<video id="company-movie" controls>
<source src="/video/movie.mp4" type="video/mp4">
</video>
腳本看起來像:
$(document).ready(function(){
// var movie = document.getElementById('company-movie');
var movie = $('#company-movie').get(0);
$('#movieModalOpenMedium').click(function(){
movie.play();
})
})
#company-movie元素在 DOM 中正確顯示,但我無法以任何方式播放它。
我試過:
$('#company-movie').play() - JQuery 對象沒有 play() 方法所以肯定它不會工作
$('#company-movie').get(0).play();
但這些方法都不起作用。
我也試圖通過這種方式在沒有 jQuery 的情況下做到這一點:
$(document).ready(function(){
var movie = document.getElementById('company-movie');
document.getElementById("movieModalOpenMedium").addEventListener("click", function(){
movie.play();
});
})
但它也不起作用。
我將不勝感激。
試試$('#company-movie')[0].play();
或$('#company-movie').get(0).play();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.