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

为什么会报错?document.getElementById('count').value=num;这句话不对?

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>计时器</title>
<script type="text/javascript">
  var num=0;
  function startCount() {    
  document.getElementById('count').value=num;    
  num=num+1;    
  setTimeout("startCount()",1000);  
  }  
  startCount();
</script>
</head>
<body>
<form>
<input type="text" id="count" />
</form>
</body>
</html>

VM1245:4 Uncaught TypeError: Cannot set property 'value' of null

    at startCount (<anonymous>:4:43)

    at <anonymous>:8:3

    at g (ceditor.js?v=201807191446:1)

    at v.runCode (ceditor.js?v=201807191446:1)

    at Object.success (ceditor.js?v=201807191446:1)

    at c (jquery.js?v=201807191446:2)

    at Object.fireWith [as resolveWith] (jquery.js?v=201807191446:2)

    at k (jquery.js?v=201807191446:4)

    at XMLHttpRequest.r (jquery.js?v=201807191446:4)


提问者:是青山 2018-07-19 22:52

个回答

  • 欧王吧
    2018-08-10 21:23:24

    你这个 input标签里面连  调用函数都没有 当然没东西了

  • 周飞飞zzz
    2018-07-20 11:37:38

    是不是把13行去掉,18行后面插入<input type="button" value="Start" onClick="startCount()">