源代碼
點擊運行
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>教程</title> </head> <head> <script> function timedText(){ var x=document.getElementById('txt'); var t1=setTimeout(function(){x.value="2 秒"},2000); var t2=setTimeout(function(){x.value="4 秒"},4000); var t3=setTimeout(function(){x.value="6 秒"},6000); } </script> </head> <body> <form> <input type="button" value="顯示文本時間!" onclick="timedText()" /> <input type="text" id="txt" /> </form> <p>點擊上面的按鈕,輸出的文本將告訴你2秒,4秒,6秒已經過去了。</p> </body> </html>
運行結果