<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<input type="text" id="txt1" />
<input type="text" id="text2" />
<input type="text" id="text3" />
</div>
</form>
</body>
</html>
<script type="text/javascript">
//此为不合理的设计
window.onload=function(){
document.getElementById("text1").focus();
}
</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server" defaultfocus="text1"><!--合理的设计,HTML加载完即定位焦点,不会等待资源加载完再定位,不会打断用户期望的焦点-->
<div>
<input type="text" id="txt1" />
<input type="text" id="text2" />
<input type="text" id="text3" />
</div>
</form>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<input type="text" id="text1" />
<script type="text/javascript">
document.getElementById("text1").focus();//期望的元素一出现,即定位焦点
</script>
<input type="text" id="text2" />
<input type="text" id="text3" />
</div>
</form>
</body>
</html>