Javascript 如何在重新加载特定div时停止闪烁
我已经使用setTimeout函数重新加载我的通知下拉列表,现在它工作正常,但我的通知下拉列表在重新加载时会闪烁,请给出任何解决方案来停止闪烁 这里我附上我已经使用过的东西Javascript 如何在重新加载特定div时停止闪烁,javascript,jquery,html,codeigniter,Javascript,Jquery,Html,Codeigniter,我已经使用setTimeout函数重新加载我的通知下拉列表,现在它工作正常,但我的通知下拉列表在重新加载时会闪烁,请给出任何解决方案来停止闪烁 这里我附上我已经使用过的东西 $(document).ready(function(){ notification(); }); function notification() { setTimeout(function() { $('#notification_ico').load('<?php ec
$(document).ready(function(){
notification();
});
function notification()
{
setTimeout(function()
{
$('#notification_ico').load('<?php echo base_url();?>/Filemanagement/noti_refresh');
notification();
}, 3000);
}
function abc() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("notification_ico").innerHTML = this.responseText;
}
};
xhttp.open("GET", "<?php echo base_url();?>/Filemanagement/noti_refresh", true);
xhttp.send();
}
$(文档).ready(函数(){
通知();
});
函数通知()
{
setTimeout(函数()
{
$('notification_ico')。加载('Filemanagement/noti_refresh');
通知();
}, 3000);
}
函数abc(){
var xhttp=newXMLHttpRequest();
xhttp.onreadystatechange=函数(){
if(this.readyState==4&&this.status==200){
document.getElementById(“notification_ico”).innerHTML=this.responseText;
}
};
xhttp.open(“GET”,“/Filemanagement/noti_refresh”,true);
xhttp.send();
}
“我的页面不工作”这里的问题是,每次调用通知时,都会调用一个新的setTimeout,而不会终止前一个setTimeout,因此最终会并行执行多个setTimeout 您应该改用setInterval:
$(document).ready(function () {
setInterval(function () {
$('#notification_ico').load('<?php echo base_url();>/Filemanagement/noti_refresh');
}, 1000);
});
$(文档).ready(函数(){
setInterval(函数(){
$(“#notification_ico”).load(“这里的问题是,每次调用notification时,都会调用一个新的setTimeout,而不会终止前一个setTimeout,因此最终会并行执行多个setTimeout
您应该改用setInterval:
$(document).ready(function () {
setInterval(function () {
$('#notification_ico').load('<?php echo base_url();>/Filemanagement/noti_refresh');
}, 1000);
});
$(文档).ready(函数(){
setInterval(函数(){
$('#notification_ico').load('您正在调用notification())重新加载inside timedout后再次调用函数,这会导致一次又一次递归调用通知函数并导致闪烁。我需要显示最近的通知,这就是为什么我在setTimeout函数中调用通知函数的原因,因此它是每隔3秒调用通知函数。您应该在中使用setInterval
您调用的不是setTimeout
通知()重新加载inside timedout后再次调用函数,这会导致一次又一次递归调用通知函数并导致闪烁。我需要显示最近的通知,这就是为什么我在setTimeout函数中调用通知函数的原因,因此它是每隔3秒调用通知函数。您应该在中使用setInterval
而不是设置超时
它不是自我刷新它不是自我刷新