fmpq.com
源代码:
点击运行
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Fmpq教程(fmpq.com)</title> </head> <body> <p id="demo">单击按钮显示此时的时间:</p> <button onclick="myFunction()">点我</button> <script> function addZero(i){ if (i<10) { i="0" + i; } return i; } function myFunction(){ var d=new Date(); var x=document.getElementById("demo"); var h=addZero(d.getHours()); var m=addZero(d.getMinutes()); var s=addZero(d.getSeconds()); x.innerHTML=h + ":" + m + ":" + s; } </script> </body> </html>
运行结果