jquery 有没有办法根据计时器更改 div 的内容。
假设我有提供“提示”的模块。提示内容应每 5 秒更改一次。
Thanks
制定一系列提示。然后做一个interval
5秒改变div的内容。我假设您想要随机提示。
请参阅 jsFiddle 上的示例。 http://www.jsfiddle.net/brunolm/CDzXQ/
var tips = [
"Tip 01",
"Tip 02",
"Tip 03",
"Tip 04",
"Tip 05",
"Tip 06",
"Tip 07",
"Tip 08",
"Tip 09"
];
// get a random index, get the value from array and
// change the div content
setInterval(function() {
var i = Math.round((Math.random()) * tips.length);
if (i == tips.length) --i;
$("#tip").html(tips[i]);
}, 5 * 1000);
See:
- 设置时间间隔 https://developer.mozilla.org/en/DOM/window.setInterval
- jQuery 选择器 http://api.jquery.com/category/selectors/
- jQuery html http://api.jquery.com/html/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)