问答详情
源自:8-5 计时器setTimeout()

计时器setTimeout()

<!DOCTYPE HTML>

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<title>计时器</title>

</head>

<script type="text/javascript">

  var num=0;

  function startCount() {

    document.getElementById('count').value=num;

    num=num+1;

    setTimeout("startCount()",1000);

  }

  setTimeout("startCount()",1000);

</script>

</head>

<body>

<form>

<input type="text" id="count" />

</form>

</body>

为什么num=num++不可以执行?

提问者:一失手成千古恨 2016-03-03 18:23

个回答

  • tyc1
    2016-03-03 19:16:26

    num=++num就可以,因为num++是先赋值再自加,所以一直是0