<input type='text' id='txtMyInputBox' />
<script language='javascript' type='text/javascript'>
function SetFocus()
{
// safety check, make sure its a post 1999 browser
if (!document.getElementById)
{
return;
}
var txtMyInputBoxElement = document.getElementById("txtMyInputBox");
if (txtMyInputBoxElement != null)
{
txtMyInputBoxElement.focus();
}
}
SetFocus();
</script>
对于那些使用。Net 框架和 asp.net 2.0或以上版本,它们都是琐碎的。如果您使用的是旧版本的框架,那么您需要编写一些与上面类似的 javascript。
在 OnLoad 处理程序中(如果使用 Visual Studio 提供的库存页面模板,通常是 page _ load) ,您可以使用: