利用定时器

    1. setInterval(function(){
    2. var oDate=new Date();
    3. var hours=oDate.getHours();
    4. var minutes=oDate.getMinutes();
    5. function transform(params){
    6. return params=params<10?"0"+params:params
    7. }
    8. document.getElementById("time").innerHTML=transform(hours)+":"+transform(minutes)
    9. },1000)
    <p id="time">21:32</p>