关于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 type="text/javascript">

setInterval(attime,1000);

function attime(){

  var time=new Date();

  i=time.getHours()+":"+time.getMinutes()+":"+time.getSeconds();

  document.getElementById("showtime").value=i;

}

setInterval(attime,1000);

function attime2(){

  var time2=new Date();

  i=time2.getHours()+":"+time2.getMinutes()+":"+time2.getSeconds();

  document.getElementById("showtime2").value=i;

}


</script>

</head>


<body>

现在时间是:<input type="text" size="40" id="showtime" />

现在时间是:<input type="text" size="40" id="showtime2" />

</body>

</html>

运算后为什么,第二个input没有显示任何东西,是被跳过了吗?还望大神指教

天瑜CJT
浏览 1203回答 1
1回答

凨亦凌

因为你第二个计时器里面调用的方法的方法名称错了,应该是setInterval(attime2,1000);才对
打开App,查看更多内容
随时随地看视频慕课网APP