<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title> </title>
</head>
<body><form name=form1>
<input name="key" id="key" value="">
<input name="text2">
</form>
</body>
<SCRIPT language=javascript>
document.getElementById('key').focus();
alert(titab);
</script>
</html>注意页面加载顺序 ,放到body后面也可以
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title> </title>
</head>
<body><form name=form1>
<input name="key" id="key" value="">
<input name="text2">
</form>
</body>
<SCRIPT language=javascript>
document.getElementById('key').focus();
alert(titab);
</script>
</html>注意页面加载顺序 ,放到body后面也可以
<input name="key" id="key" value=""> 当执行document.getElementById('key').focus()时
<input name="key" id="key" value=""> 还没有被加载到document对象里