[英]setInterval and function
I have written this simple function: 我写了这个简单的函数:
HTML: HTML:
<div class="mhead">
<div class="mTop">
<a class="headline" title="" href="">
<img alt="" src="">
<span> </span>
</a>
</div>
<div class="tNav">
<ul id="topt" class="tUl">
<li title="http://www.site.com/761028497.jpg"> <a title="" href="">1</a> </li>
<li title="http://www.site.com/761028497.jpg"> <a title="" href="">2</a> </li>
</ul>
</div>
Function: 功能:
$.fn.inters = function (target) {
this.find('li').hover(function () {
var head = $(this).find('a').attr('title');
var image = $(this).attr('title');
var href = $(this).find('a').attr('href');
$(target).find('img').attr('src', image);
$(target).find('img').attr('alt', head);
$(target).attr('href', href);
$(target).attr('title', head);
$(target).find('span').html(head);
}).eq(0).hover();}
$("#topt").inters('.headline');
I want to add setInterval
to this script: 我想在此脚本中添加
setInterval
:
$(function() {
setInterval( "inters()", 3000 );
});
But the headline items doesnt change. 但标题项目并没有改变。 How can I make change in
inters
function every 3000 ms? 我怎样才能使变革
inters
功能每隔3000毫秒?
Thanks in advance 提前致谢
Your setInterval
will attempt to call the function inters()
every 3 seconds, which is probably not what you want. 你的
setInterval
将尝试每隔3秒调用一次函数inters()
,这可能不是你想要的。
What I think you want to execute is the following line: 我认为你想要执行的是以下行:
$('#topt').inters('.headline');
If you want to do so you should create a function that will execute that line, like so: 如果你想这样做,你应该创建一个将执行该行的函数,如下所示:
setInterval(function() {
$('#topt').inters('.headline');
}, 3000);
The above will call $('#topt').inters('.headline');
以上将调用
$('#topt').inters('.headline');
every 3 seconds. 每3秒钟一次。
you need to do something in this way: 你需要以这种方式做某事:
function foo(){
$("#topt").inters('.headline');
}
setInterval(foo,3000);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.