<!doctype html>
<html>
<head>
<style>
#test1{
width:221px;
}
</style>
<script>
function setfocus(){
var test2=document.getElementById("test2");
test2.focus();//focus()函数,使元素获得焦点。blur()函数使元素失去焦点;
}
</script>
<meta charset="UTF-8">
</head>
<body>
<fieldset id="test1">
<legend>
autofocus属性:
</legend>
<p>账户:<input type="text" id="test2" autofocus="true"></p><!--设置autofocus属性为true后,可以在页面加载完成时使元素获得焦点-->
<p>密码:<input type="text" id="test3" autofocus="true"></p><!--如果所有元素都设置了autofocus属性,则页面加载完成时,第一个设置了autofocus属性的元素获得焦点-->
   <input type="button" value="提交" οnclick="setfocus()">  <input type="button" value="取消">
</fieldset>
</body>
</html>
<html>
<head>
<style>
#test1{
width:221px;
}
</style>
<script>
function setfocus(){
var test2=document.getElementById("test2");
test2.focus();//focus()函数,使元素获得焦点。blur()函数使元素失去焦点;
}
</script>
<meta charset="UTF-8">
</head>
<body>
<fieldset id="test1">
<legend>
autofocus属性:
</legend>
<p>账户:<input type="text" id="test2" autofocus="true"></p><!--设置autofocus属性为true后,可以在页面加载完成时使元素获得焦点-->
<p>密码:<input type="text" id="test3" autofocus="true"></p><!--如果所有元素都设置了autofocus属性,则页面加载完成时,第一个设置了autofocus属性的元素获得焦点-->
   <input type="button" value="提交" οnclick="setfocus()">  <input type="button" value="取消">
</fieldset>
</body>
</html>