English 中文(简体)
某些间距时刷新imig
原标题:Refresh img at some interval

我在我的jsp档案里有跟踪Div

<div id="myDiv">
    <img alt="" src="http://localhost:8080/chartDemo/servlet/ChartDemoServlet">
</div>

我想在某个间隔内自动刷新图像 。

我尝试了 的操作非常完美, 但可以刷新整页 。

我怎样才能只刷新图像呢?

最佳回答
<div id="myDiv" onload="JavaScript:timedRefresh(5000);">
        <img alt=""
            src="http://localhost:8080/chartDemo/servlet/ChartDemoServlet">
    </div>

把它放在喷射针中

function timedRefresh(timeoutPeriod) {
    setTimeout("location.reload(true);",timeoutPeriod);
}
问题回答

我想在某个间隙自动刷新该 div 。

用什么内容? 或者每次 img 都会更改吗?

如果是:

setInterval(function() {
    $("#myDiv").html( <img alt="" src="http://localhost:8080/chartDemo/servlet/ChartDemoServlet"> );
}, 1000);

...如果 < code> img s < code> src < /code > URL 返回的数据的缓存信头是正确的(否则,浏览器可以缓存较早版本),那么完全撕掉 < code> div 的内容,然后为其指定标记,该标记应重新创建 < code> img < /code > 元素,并导致再展(如果信头是对的,则会增加)。

setInterval(function() {
  // use to prevent browser cache
  var d = new Date();
  $("#myDiv img").attr("src", "http://localhost:8080/chartDemo/servlet/ChartDemoServlet?"+d.getTime());
}, 3000); // every 3 seconds.

You need to use window.setInterval timer. In that function you give change the img src. soemthing like this

//timer function
window.setInterval(refreshImage,1000);

function refreshImage()
{
     $( #urdiveid img ).attr( src )= new location ;
}

可以用 JavaScript 超时函数完成

var t=setTimeout("functiontoCall()", 3000)

您可以在 FunctiontoCall () 中以 myDiv 输入内容。 它可以是ajax调用或简单的 Dom 操作 。





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签