Php Onmouseover数据保持自动刷新
我的代码如下所示:Php Onmouseover数据保持自动刷新,php,javascript,jquery,Php,Javascript,Jquery,我的代码如下所示: $(document).ready(function() { $("#content2").load("post_rf.php"); // set your initial interval to kick it off var refreshInterval = setInterval(function() { $("#content2").load('post_rf.php?randval='+ Math.random());
$(document).ready(function() {
$("#content2").load("post_rf.php");
// set your initial interval to kick it off
var refreshInterval = setInterval(function() {
$("#content2").load('post_rf.php?randval='+ Math.random());
}, 1500);
// bind an event to mouseout of your DIV to kickstart the interval again
$("#content2").bind("mouseout", function() {
refreshInterval = setInterval(function() {
$("#content2").load('post_rf.php?randval='+ Math.random());
}, 1500);
});
// clear the interval on mouseover of your DIV to stop the refresh
$("#content2").bind("mouseover", function() {
clearInterval(refreshInterval);
});
$.ajaxSetup({
cache: false
});
});
我想做的是当鼠标滑过时,数据保持自动刷新。
在这种情况下,如果我将鼠标拖动到mouseover
区域,它将停止自动刷新,直到我将mouseout
拖动到mouseover
区域
那么,是否可以在MouseOver上设置
,数据将保持自动刷新?我想你想要的是另一种方式
$("#content2").bind("mouseover", function() {
refreshInterval = setInterval(function() {
$("#content2").load('post_rf.php?randval='+ Math.random());
}, 1500);
});
// clear the interval on mouseover of your DIV to stop the refresh
$("#content2").bind("mouseout", function() {
clearInterval(refreshInterval);
});
我对你的问题有点困惑,下面的代码负责在你鼠标滑过时停止自动刷新
$("#content2").bind("mouseover", function() {
clearInterval(refreshInterval); // it's clearing the setInterval
});
如果您只是删除/禁用行或整个功能,那么当您在该元素上移动鼠标时,它不会停止自动刷新
但是如果您只想在mouseover
上进行auti刷新,并且再次想在mouseout
上停止自动刷新,则可以执行以下操作
$("#content2").bind("mouseover", function() {
refreshInterval = setInterval(function() {
$("#content2").load('post_rf.php?randval='+ Math.random());
}, 1500);
});
$("#content2").bind("mouseout", function() {
clearInterval(refreshInterval);
});
/*
var refreshInterval = setInterval(function() {
$("#content2").load('post_rf.php?randval='+ Math.random());
}, 1500);
*/
并且不应该使用下面的代码来启动自动刷新,只需按如下方式禁用代码
$("#content2").bind("mouseover", function() {
refreshInterval = setInterval(function() {
$("#content2").load('post_rf.php?randval='+ Math.random());
}, 1500);
});
$("#content2").bind("mouseout", function() {
clearInterval(refreshInterval);
});
/*
var refreshInterval = setInterval(function() {
$("#content2").load('post_rf.php?randval='+ Math.random());
}, 1500);
*/
但是您可以将变量declarede保持为var refreshInterval=0代码>您好,谢谢您的回复。这不是我想要的。想象一下,在内容区我有一个文本框,所以如果我想输入文本框,我肯定必须快速输入,因为它会刷新并清除文本框,对吗?我不确定我是否理解你,你希望div中除了文本框以外的其他元素继续刷新??嗨,谢谢你的回答。这不是我想要的。想象一下,在内容区我有一个文本框,所以如果我想输入文本框,我必须快速输入,因为它会刷新并清除文本框。你想只在你想输入文本框时停止自动刷新,并在你聚焦文本框时再次启用它吗?这正是我的意思,但是如果我在文本框中键入,autorefresh是否可以继续运行?实际上是$(“#content2”)。bind(“mouseover”,function(){…})
将停止它,但当您在文本框中聚焦时,可以再次启动它。