js小问题
我的代码是:
<!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=utf-8" />
<title>测试按键</title>
<style>
#write{
width:200px;
height:30px;
top:200px;
left:1200px;
border:1px solid red;
background:#090;
}
</style>
<script src="js/jquery-1.3.2.js"></script>
<script>
var temp="";
$(document).ready(function(){
$(document).keydown(function(evt){
var code = evt.keyCode;
//转换成数字
change(code);
//alert(temp)
if(temp>=200){
temp = "";
}
//writeOut(temp);
setTimeout(writeOut(temp),3000);
});
});
function change(code){
//alert(code)
//键值对应数字0
if(code==48){
temp += 0;
}
if(code==49){
temp += 1;
}
if(code==50){
temp += 2;
}
if(code==51){
temp += 3;
}
if(code==52){
temp += 4;
}
if(code==53){
temp += 5;
}
if(code==54){
temp += 6;
}
if(code==55){
temp += 7;
}
if(code==56){
temp += 8;
}
//键值对应数字9
if(code==57){
temp += 9;
}
else{
return;
}
return temp;
}
function writeOut(temp){
$("#write").html(""+temp+"");
}
</script>
</head>
<body>
<div id="write"></div>
</body>
</html>
我遇到的问题:我用setTimeout函数会出错,不知道是怎么回事,原来也是这样用的,在FF下运行的