關于變量賦值的問題
<html>
<head>
<meta?http-equiv="Content-Type"?content="text/html;?charset=utf-8">
<title>計時器</title>
<script?type="text/javascript">
???var?i=setInterval(clock,100);???//位置1
???function?clock(){
??????var?time=new?Date();?????????????????????
??????document.getElementById("clock").value?=?time.getHours()+":"+time.getMinutes()+":"+time.getSeconds();
???}
???
???function?start(){
?????i=setInterval("clock()",100);??//位置2
???}
???function?stop(){
???????clearInterval(i);
???}
</script>
</head>
<body>
??<form>
????<input?type="text"?id="clock"?size="50"??/>
????<input?type="button"?value="Start"??onclick="start()"/>
????<input?type="button"?value="Stop"??onclick="stop()"/>
??</form>
</body>
</html>代碼中位置1 i變量已經賦值為什么 位置2的function中仍然要賦值?
2015-12-02
setInterval()是個方法。
位置1中觸發了這個開始。所有input里面是自動刷新的。
位置2種start觸發了開始,所有也是繼續刷新的
個人看法