friend
我有以下代码来刷新以下 DIV id refreshDiv 以每 5 秒自动刷新一次,但它不起作用
<div id ="refreshDiv" class="span2" style="text-align:left;">
<c:set var="map" value="${alertStatusForm.channelStateForRecipients[currentChannel]}"></c:set>
<div>
<label><img src="${channelIcon}">
${fn:length(map['DELIVERED'])}</label>
</div>
<div>
<label><img src="${channelIcon}">
${fn:length(map['FAILED'])}</label>
</div>
<div>
<label><img src="${channelIcon}">
${fn:length(map['IN_PROGRESS'])}</label>
</div>
</div>
function refreshDiv(){
$.ajax({
url: 'editReg.jsp'
}).done(function(result) {
$('#refreshDIV').text(result);
});
}
最佳答案
您没有调用 refreshDiv()
。你刚刚定义了它。加载 dom 时调用此函数,并使用 setTimeout
每 5 秒后继续调用。
$(function(){
function refreshDiv(){
$.ajax({
url: 'editReg.jsp'
}).done(function(result) {
$('#refreshDIV').text(result);
window.setTimeout(refreshDiv, 5000);
});
}
window.setTimeout(refreshDiv, 5000);
});
关于javascript - 每 5 秒自动刷新一个 DIV 代码不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17895624/