js調用函數時括弧加與不加的區別,function()&function

來源:互聯網
上載者:User

標籤:minutes   array   class   text   body   htm   log   window   lin   

<!DOCTYPE HTML><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>當前系統時間</title><link rel="stylesheet" href="style.css"  /><script language="javascript" type="text/javascript">  window.onload = function(){    showTime();  };  function checkTime(i){  //補位處理      if(i<10){          i="0"+i;            }      else{return i;}  }  function showTime(){    var now=new Date();    var year=now.getFullYear();    var month=now.getMonth();    var day=now.getDate();    var h=now.getHours();    var m=now.getMinutes() ;    var s= now.getSeconds() ;    m=checkTime(m);    s=checkTime(s);    var weekday=new Array(7);    weekday[0]="星期日";    weekday[1]="星期一";    weekday[2]="星期二";    weekday[3]="星期三";    weekday[4]="星期四";    weekday[5]="星期五";    weekday[6]="星期六";    document.getElementById("show").innerHTML=""+year+"年"+month+"月"+day+"日 "+weekday[now.getDay()]+h+":"+m+":"+s;    t=setTimeout(‘showTime()‘,1000);    /*t=setTimeout(showTime,1000);也可以,同樣效果*/    /*t=setTimeout(showTime(),1000);不行,直接調用了函數的結果(也就是一個固定值),一開始就跑出了結果然後賦值給了t,相當於t=setTimeout(運行程式時的時間,1000)*/  }</script></head><body><div class="content1">  <div id="show">顯示時間的位置</div></div></body></html>

 

js調用函數時括弧加與不加的區別,function()&function

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.