87,907
社区成员
发帖
与我相关
我的任务
分享
<script type="text/javascript">
var s="";
var index = 0;
var i = 0;
document.onkeypress =function(){
setTimeout("setVal()",1000);
i++;
}
function setVal(){
index ++;
if(index==i) {
s = document.getElementById("txt1").value;
alert(s);
index = 0;
i=0;
}
}
</script>
<input type=text id="txt1">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<script language="javascript">
function searchKeyWord(id) {
this.element = document.getElementById(id);
this.timeID = null;
this.init();
}
searchKeyWord.prototype = {
init: function() {
var _self = this;
this.element.onkeyup = function() {_self.start()};
this.element.onblur = function() {_self.end()};
},
start: function() {
this.resetTime();
var _self = this;
this.timeID = setTimeout(function(){_self.end()}, 1000);
},
end: function() {
if(this.timeID) {
this.resetTime();
this.searchIt();
}
},
resetTime: function() {
clearTimeout(this.timeID);
this.timeID = null;
},
searchIt: function() {
var _value = this.element.value.replace(/(^\s*)|(\s*$)/g, '');
document.getElementById('t').value = _value;
}
}
</script>
<body>
<input type="text" id='keyWord' />
<input type="text" id='t' />
<script language="javascript">
new searchKeyWord('keyWord');
</script>
</body>
</html>
<script type="text/javascript">
var s="";
document.onkeypress =function(){
s+=String.fromCharCode(event.keyCode);
}
function setVal(){
document.getElementById("txt1").value=s;
s="";
}
setTimeout("setVal()",3000);
</script>
<input type=text id="txt1">