文本框自动获取焦点的两种方式
1、html5的autofocus属性
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
图书:<input type="text" name="book"><br/>
价格:<input type="text" name="price" autofocus>
</body>
</html>
2、通过js的focus()方法
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
图书:<input type="text" name="book"><br/>
价格:<input type="text" name="price" id="price">
<script>
document.getElementById("price").focus();
</script>
</body>
</html>