只是一個簡單的問題。TypeError:未能在'HTMLMediaElement'上執行'play':非法調用
我想爲變量指定一個HTMLMediaElement
方法。
// html part
<video id="player" ... />
// js part
const video = document.querySelector('#player')
const play = video.play
video.play() // works!
play() // error!
Uncaught (in promise) TypeError: Failed to execute 'play' on 'HTMLMediaElement': Illegal invocation
有人知道爲什麼會發生這個錯誤嗎?
我想你需要將'this'綁定到'video'? ---是的,綁定的作品,'玩= play.bind(視頻)' – evolutionxbox
這個問題感覺它是重複的...但我找不到一個愚蠢的目標。 – evolutionxbox
如果你沒有找到以前的問題。您可以將答案發布到回答塊。 – WendellLiu