我有一个文本框,内容在页面重新加载时更改,但我想知道的是如何在指定的时间后更改它。这可能没有闪光灯吗?
答案 0 :(得分:2)
将此代码复制并粘贴到html文件中并检查出来,应该很容易编辑以满足您自己的需要。享受:o)
<html>
<head>
<script type="text/javascript">
//Change these messages to what ever you would like to display in the textbox
//You can add or remove any as you see necessary
var messages = new Array(
"Hello",
"there",
"my",
"name",
"is",
"Chief17!"
);
var i = 0;
function changeText()
{
document.getElementById("tb").value = messages[i];
if(i < messages.length -1)
{
i++;
}
else
{
i = 0;
}
}
</script>
</head>
<!--Change the 1000 to how long you want to wait in between message changes (1000 is 1 second)-->
<body onLoad="setInterval('changeText()',1000)">
<input type="text" id="tb" />
</body>
</html>
答案 1 :(得分:1)
setInterval('changeTextFunction()',1000);
第二个参数,1秒= 1000。
答案 2 :(得分:1)
要更改文本框中的文字,您可以
txtFld = document.getElementById("yourTextBox");
txtFld.value = "New value";
要像倒数计时器一样设置计时器,您可以使用以下内容的变体:
<script>
<!--
//
var milisec=0
var seconds=30
document.counter.d2.value='30'
function display(){
if (milisec<=0){
milisec=9
seconds-=1
}
if (seconds<=-1){
milisec=0
seconds+=1
}
else
milisec-=1
document.counter.d2.value=seconds+"."+milisec
setTimeout("display()",100)
}
display()
-->
</script>