gpt4 book ai didi

Javascript 图像刷新

转载 作者:行者123 更新时间:2023-11-30 18:20:01 25 4
gpt4 key购买 nike

我正在使用以下代码尝试刷新我网站上的两个网络摄像头图像。

var t_webcam = 60 // interval in seconds 
image_webcam = "cam_1.jpg" //name of the image
function Start_webcam() {
tmp_webcam = new Date();
tmp_webcam = "?"+tmp_webcam.getTime()
document.images["frontcam"].src = image_webcam+tmp_webcam
setTimeout("Start_webcam()", t_webcam*1000)
}
Start_webcam();

在网站上,我使用以下代码行调用该函数

然而,当我将它加载到网站上时,出现以下错误并且它不起作用,

Uncaught TypeError: Cannot set property 'src' of undefined

如果有人对 Javascript 有更多的了解并且能够提供一些帮助,我将不胜感激。

谢谢理查德

最佳答案

document.images 是一个数组,所以它只接受数字索引。您正在尝试像访问字典一样访问它,将 frontcam 作为键传递。

如果您的标签如下所示,您可以使用 document.getElementById:

<img src="sth.jpg" id="frontcam"></img>

关于Javascript 图像刷新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12288542/

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