如何让输入框获得焦点?

来源:百度知道 编辑:UC知道 时间:2024/06/20 05:10:04
<input name="loginN" id="loginN" type="text" size="16">;我希望一开始它就可以获取焦点

吧<body>改成:
<body onload="document.getElementById('loginN').focus()">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>获得焦点</title>
</head>
<body onload="javascript:document.getElementById('loginN').focus();">
<form id="form1" runat="server">
<div>
<input name="loginN" id="loginN" type="text" size="16" />
</div>
</form>
</body>
</html>

在body标签里加上onLoad="javascript:init();" //此为页面加载时执行

function init(){
document.getElementById("loginN").focus();
}