我正在使用以下 JavaScript / html 在 Chrome 中播放視頻。
控制臺記錄“Uncaught SyntaxError: Unexpected end of input”。
我看不出我做錯了什么。我的錯誤是什么?
謝謝!
<html>
<head><meta name="viewport">
<style>
video
{
position: relative;
}
</style>
</head>
<body>
<video ontouchstart="playPause()" controls="controls" poster="" video width="100%" height="auto" autoplay id="vid">
<source id="somefileID" src="file:///d:/dev/videos/Das Krokodil-Lied.mp4" type='video/mp4; codecs="avc1.42E01E, mp4a.40.2"' />
</video>
<script>
function playPause(e)
{
if (!document.getElementById("myVideo"))
{
alert("Element does not exist. Let's create it.");
}
var myVideo = document.getElementById("vid");
if (myVideo = null)
{
alert('video is null!');
}
else
{
if (myVideo.paused)
{
myVideo.play();
}
else
{
myVideo.pause();
}
}
</script>
</body>
</html>
uj5u.com熱心網友回復:
你有幾個問題:
- 您錯過了代碼中的最后一個大括號。使用良好的標簽結構將幫助您更容易地看到缺少大括號的位置。
- 您使用分配
=而不是==
在下面尋找****:
function playPause(e)
{
if (!document.getElementById("myVideo"))
{
alert("Element does not exist. Let's create it.");
}
var myVideo = document.getElementById("vid");
if (myVideo == null) // **** You probably mean == ****
{
alert('video is null!');
}
else
{
if (myVideo.paused)
{
myVideo.play();
}
else
{
myVideo.pause();
}
}
} // **** MISSING ****
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/475275.html
標籤:javascript html 谷歌浏览器
