setInterval和函数 [英] setInterval and function
本文介绍了setInterval和函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经编写了这个简单的函数:
I have written this simple function:
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>
功能:
$.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');
我要在该脚本中添加setInterval
:
$(function() {
setInterval( "inters()", 3000 );
});
但是标题项没有改变.如何每3000毫秒在inters
函数中进行更改?
But the headline items doesnt change. How can I make change in inters
function every 3000 ms?
预先感谢
推荐答案
您的setInterval
将尝试每3秒调用一次函数inters()
,这可能不是您想要的.
Your setInterval
will attempt to call the function inters()
every 3 seconds, which is probably not what you want.
我认为要执行的是以下行:
$('#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);
以上将每3秒调用一次$('#topt').inters('.headline');
.
The above will call $('#topt').inters('.headline');
every 3 seconds.
这篇关于setInterval和函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文