源代码:
下载代码
点击运行
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>菜鸟教程(runoob.com)</title> </head> <body> <p>点击按钮,在第 2、4、6 秒修改输入框中的文本:</p> <button onclick="timedText()">显示时间文本</button> <input type="text" id="txt"> <script> function timedText() { var x = document.getElementById("txt"); setTimeout(function(){ x.value="2 秒" }, 2000); setTimeout(function(){ x.value="4 秒" }, 4000); setTimeout(function(){ x.value="6 秒" }, 6000); } </script> </body> </html>
运行结果: