<html>
<head>
<title>关中游侠——.Net中TextBox获得焦点的方法</title>
</head>
<body>
<form >http://hi.baidu.com/activezfj</a>
<br />
<!--
在这里加入脚本
-->
</form>
</body>
</html>
方法一:
将“在这里加入脚本”替换为:document.Form1.txtWords.focus();
方法二:
将“在这里加入脚本”替换为:document.getElementById('<%=txtWords.ClientID%>').focus();
方法三:
CEdit *p=(CEdit*)GetDlgItem(编辑框的ID);
p.SetFocus();
方法四:
给这个编辑框定义一个CEdit类型的变量,比如m_edit;
在需要的地方,用m_edit.SetFocus()就可以了。
就可以搞定了
function text_focus() { window.form1.textbox1.focus(); } 在aspx页面中onload_keydown事件中使用该函数
Button1.Attributes.Add("onclick", "javascript:document.all.kongjianId.focus();")