- <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
- <%
- String path = request.getContextPath();
- String basePath = request.getScheme() + "://"
- + request.getServerName() + ":" + request.getServerPort()
- + path + "/";
- %>
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
- <html>
- <head>
- <base href="<%=basePath%>">
- <title>获得焦点</title>
- <meta http-equiv="pragma" content="no-cache">
- <meta http-equiv="cache-control" content="no-cache">
- <meta http-equiv="expires" content="0">
- <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
- <meta http-equiv="description" content="This is my page">
- <!--
- <link rel="stylesheet" type="text/css" href="styles.css">
- -->
- <script language=javascript type=text/javascript>
- function fc(){
- document.getElementById("t1").focus();//自己定义ID 然后指定获取焦点的id
- }
- </script>
- </head>
- <body onload="fc()">
- <form method="post" name="login" action="">
- 用户名:
- <input type="text" id="t1" name="t1" size="20">
- 密 码:
- <input type="password" id="t2" name="t2" size="20">
- <input type="submit" value="提交">
- <input type="reset" value="重置">
- </form>
- </body>
- </html>
或者在body标签里面,直接写:
- <body onload="document.forms.form_name.form_field.focus()">
注:form_field为<input 标签的name。