<!--
point 0:
需要为你的控件添加 onfocus 和 onblur 事件,触发状态参数的修改
-->
<input type="text" ID="typeWriter" onfocus="stopIt()" onblur="continueIt()">
<script>
var arr = ["显示文本1","显示文本2","显示文本3","显示文本4","显示文本5","显示文本6"];
var index = 0;
typeWriter.value = arr[index];
// point 1 :
// setInterval 会创建一个无限循环的过程
// setTimeout 会创建一个延时过程
// 很明显你需要的是 setTimeoutsetTimeout(_checkIfNeedTextChange,3000);// point 2:
// 定义一个状态参数(全局)
var _isStop = false;function disp(obj){
if(index<arr.length-1){
index++;
}else{
index = 0;
}
typeWriter.value = arr[index];
}
// point 3:
// 创建一个过程控制方法,根据状态参数 _isStop 控制程序执行过程
function _checkIfNeedTextChange(){ if(_isStop){
// point 4 : 需求不是很明确 
// 如果 input输入完成,失去焦点的时候,要求文本能够继续随机显示,就需要下面这句
// 否则不需要
// setTimeout(_checkIfNeedTextChange,3000);
} else {
var _input = document.getElementById("typeWriter");
disp(_input);
setTimeout(_checkIfNeedTextChange,3000);
}
}// poing 5
function stopIt(){
_isStop = true;
}function continueIt(){
_isStop = false;
}
</script>

解决方案 »

  1.   

    <html><title>计算前十位斐波那契数值</title>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312"><script language="javascript">
    function func2(){
    var case3;
    var case2;
    alert("2")
    }
    function func1(){
    var case1;
    var case2;
    alert("1")
    setTimeout("func2()",5000);
    }</script></head>
    <body>
    <Form name = "frm1" >
    <input type = "text" name = "txt1">
    <input type = "button" name = "btn1" value = "确定" onclick="func1()">
    </Form>
    </body></html>