gpt4 book ai didi

javascript - 我是初学者,我应该如何实现这段javascript代码?

转载 作者:行者123 更新时间:2023-11-28 07:39:18 25 4
gpt4 key购买 nike

我在谷歌上找到了这段代码,据说这段代码可以在 html 5 视频中进行搜索,我是一个完全的初学者,但我陷入了困境:

seekToTime:function( value )
{
var seekToTime = this.videoPlayer.currentTime + value;
if( seekToTime < 0 || seekToTime > this.videoPlayer.duration )
return;

this.videoPlayer.currentTime = seekToTime;
}

我尝试过这样修改,但不起作用,

seekToTime:function( value )

{
var videoPlayer = document.getElementById("videoplayer");
var seekToTime = this.videoPlayer.currentTime + value;
if( seekToTime < 0 || seekToTime > this.videoPlayer.duration )
return;

this.videoPlayer.currentTime = seekToTime;
}

当我在 html 的 head 中实现修改后的代码时,视频根本无法播放。请告诉我应该如何实现,谢谢...

最佳答案

您正在尝试访问 this.videoPlayer,其中 this 引用 Window 对象,并且您尚未在窗口上声明 videoPlayer。相反,您需要修改:

var seekToTime = this.videoPlayer.currentTime + value;

至:

var seekToTime = videoPlayer.currentTime + value;

this.videoPlayer 的任何其他引用都应变为 videoPlayer。变量 videoPlayer 可以被访问,因为您已在第一行中将其声明为函数的局部变量。

关于javascript - 我是初学者,我应该如何实现这段javascript代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28248051/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com