作为jQuery的初学者,我遵循jQuery For Designers(J4D)的教程,正如Rzetterberg所说的在webcam image refresh with ajax这篇文章中看到的。jQuery从IPCam获取jpeg图像
我从本地IPCamera获取的图像正确显示,但在每次重新载入函数后,新获取的图像将放置在先前获取的图像下方。作为这个的结果,我得到一个页面,其中每个获取的图像被放置在彼此之下。
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
$(document).ready(function() {
var refreshId = setInterval(function() {
url = 'http://xxx.xxx.xxx.xxx?randval=';
var randval = Math.random();
var img = new Image();
$(img).load(function() {
$(this).hide();
$('#ipcam').removeClass('loading').append(this);
$(this).show();
}).error(function() {
// notify the user that the image could not be loaded
}).attr('src', url + randval);
}, 1000);
$.ajaxSetup({ cache: false });
});
</script>
</head>
<body id="page">
<div id="ipcam" class="loading">
</div>
</body>
</html>
有谁知道我应该怎么做才能将新的图像放在div容器中,名为“ipcam”,正确吗?
既然它有效,请将devnull69的答案标记为已接受。 – dgvid 2012-01-13 17:03:38