<!--
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>
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>
解决方案 »
- 怎么利用坐标来定位一个div
- LODOP打印控件自动分页失效
- javascript动态往select中插入大量option速度会非常慢
- showModelessDialog 打开窗口在ie6,ie7中高度不一样怎么处理一下谢谢
- 替换
- .\b. 匹配 @@@abc 中的 @ab怎么解释啊?
- 选下拉框时,清空文本框
- 如何有JS 获取由Web Service返回的xlm中的项目
- 在Mozilla下怎样实现Alpha blending效果?
- 一个怪问题!iFrame内的页面见设置了自动刷新,但如果父页面一按超链,刷新就莫名其妙停止?
- 求助,img元素用onolod时间控制宽度
- 压缩过的js文件如何在恢复
<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>