用setTimeout实现的自动变化显示随机数的效果:
<html>
<head>
<script>
window.onload=sett;
function sett()
{
document.body.innerHTML=Math.random();
setTimeout("sett()",500);
}
</script>
</head>
<body>
</body>
</html>
[setInterval]
setInterval(表达式,交互时间)
则不一样,它从载入后,每隔指定的时间就执行一次表达式
用setInterval实现的自动变化显示随机数的效果:
<html>
<head>
<script>
function sett()
{
document.body.innerHTML=Math.random();
}
setInterval("sett();", 500);
</script>
</head>
<body>
</body>
</html>
Jquery中的setInterval
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script language="javascript" src="jquery.js"></script>
<script language="javascript">
$(function()
{
$.extend({
show:function(){
$("#test").html(Math.random());
}
});
setInterval("$.show()",300);
})
</script>
</head>
<body>
<div id='test'></div>
</body>
</html>
window.setInterval 与 window.setTimeout的区别
最新推荐文章于 2020-07-14 09:49:12 发布