jquery“everyTime”函数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3860349/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
jquery "everyTime" function
提问by Kyle
I'm trying to refresh my recent list every 5 seconds. I was looking at ajax and found jquery.
我正在尝试每 5 秒刷新一次我最近的列表。我在看 ajax 并找到了 jquery。
I found a function known as "everyTime"
我发现了一个名为“everyTime”的函数
This is what I have so far, I don't really know how to get it to work... It's not working:\
这是我到目前为止所拥有的,我真的不知道如何让它工作......它不起作用:\
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
$(document).everyTime(5s, function(i) {
<?php include "recent.php";?>
}, 0);
</script>
</head>
<body>
<div id="testDiv">
<h2>This is default. Waiting for refresh</h2>
</div>
</body>
回答by wxs
everyTime seems to be a jQuery plugin that has a lot of functionality you're not using here. For what you're doing, you can just use setInterval
thus:
everyTime 似乎是一个 jQuery 插件,它有很多你在这里没有使用的功能。对于你正在做的事情,你可以setInterval
这样使用:
setInterval(function() {
// refresh list
}, 5000)
where the second parameter is the number of milliseconds.
其中第二个参数是毫秒数。
Note on everyTime
每次都注意
If you reallywant to use everyTime, you'll need to make your first parameter a string, that is:
如果您真的想使用everyTime,则需要将第一个参数设为字符串,即:
$(document).everyTime("5s", function(i) { }, 0);
Note the quotes around the 5s. You'll also need to include the appropriate javascript file for the plugin (not just for jQuery) at the top, i.e.
注意 5s 周围的引号。您还需要在顶部包含插件(不仅仅是 jQuery)的适当 javascript 文件,即
<script type="text/javascript" src="/js/jquery.timers.js"></script>
回答by Mark Elliot
5s
is neither an integer or a string, and so it's an invalid input. To achieve the desired behavior you can use an integer number of milliseconds:
5s
既不是整数也不是字符串,因此它是无效输入。要实现所需的行为,您可以使用整数毫秒:
$(document).everyTime(5000, function(i) {
<?php include "recent.php";?>
}, 0);
or a string indicating the interval:
或指示间隔的字符串:
$(document).everyTime('5s', function(i) {
<?php include "recent.php";?>
}, 0);
(here's a reference)
(这里有一个参考)
回答by Abhijith Sasikumar
You can use everyTime plugin with jQuery Ajax like this:
你可以像这样在jQuery Ajax中使用everyTime插件:
var j = jQuery.noConflict();
j(document).ready(function()
{
j(".refresh").everyTime(1000,function(i){
j.ajax({
url: "refresh.php",
cache: false,
success: function(html){
j(".refresh").html(html);
}
})
})
});
Late answer. Hope this will help users researching on similar functions.
迟到的答复。希望这将有助于用户研究类似功能。