我只想每 5 秒检查一次远程图像,但无法使其工作。
<script>
var img = new Image();
var url = "http://192.168.20.99/led/intro2.gif";
img.onload = function(){
// display image or whatever you need
};
img.onerror = function(){
alert("HOT BERRY IS NOT CONNECTED");
// handle the error
}
img.src = url;
5000;
</script>
最佳答案
您可以根据您的要求使用setTimeout
/setInterval
。
setTimeout(function() {
$('#test').attr("src", url);
}, 5000);
var img = new Image();
var url = "http://a9.vietbao.vn/images/vn899/55/2018/04/20180405-nu-sinh-sai-thanh-gay-sot-vi-giong-hot-girl-dep-nhat-han-quoc-1.jpg";
img.onload = function(){
// display image or whatever you need
setTimeout(function() {
$('#test').attr("src", url);
}, 5000);
};
img.onerror = function(){
alert("HOT BERRY IS NOT CONNECTED");
// handle the error
}
img.src = url;
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<img id='test' width="200px"/>
关于javascript - 每 5 秒在后台检查一次远程图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57815337/