Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/88.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript setInterval在Internet Explorer中不工作_Javascript_Jquery_Html - Fatal编程技术网

Javascript setInterval在Internet Explorer中不工作

Javascript setInterval在Internet Explorer中不工作,javascript,jquery,html,Javascript,Jquery,Html,使用setInterval调用函数刷新html正文中的网络摄像头图像时。这在Chrome上运行得很好,但是在InternetExplorer中,图像不会刷新。这是因为缓存问题吗 <img id='camA' class='webcamStill' src='http://10.0.0.157/jpg/image.jpg' alt='Cam Image' /> window.setInterval(refreshWebcam, 3000); function refreshWebc

使用setInterval调用函数刷新html正文中的网络摄像头图像时。这在Chrome上运行得很好,但是在InternetExplorer中,图像不会刷新。这是因为缓存问题吗

<img id='camA' class='webcamStill' src='http://10.0.0.157/jpg/image.jpg' alt='Cam Image' />

window.setInterval(refreshWebcam, 3000);

function refreshWebcam()
{
    $('#camA').attr('src', 'http://10.0.0.157/jpg/image.jpg');
}

设置间隔(刷新网络摄像头,3000);
功能刷新网络摄像头()
{
$('#camA').attr('src','http://10.0.0.157/jpg/image.jpg');
}

绝对正确。您正在将源设置为它已经存在的状态,因此它实际上没有改变,因此就浏览器而言,不需要更新

要实现此目标,只需执行以下操作:

document.getElementById('camA').src =
                           "http://10.0.0.157/jpg/image.jpg?x="+new Date().getTime();

我用它是因为原因。

我在发帖后就发现了这一点!我将荣幸地回答你。我将url字符串与
“?”+Math.Random()
:)连接在一起,我以前使用
Math.Random()
,但总是有无限小的机会获得相同的内容两次。使用当前时间保证不会两次获得相同的内容(假设您不是每秒多次重新加载)