您的位置:首页 > 其它

.Net中TextBox获得焦点的方法

2011-07-03 23:53 183 查看
<html>
<head>
<title>关中游侠——.Net中TextBox获得焦点的方法</title>
</head>
<body>
<form id="Form1" method="post" runat="server">
.Net中TextBox获得焦点的方法<br />
<asp:textbox id="txtWords" runat="server" Width="100%" TextMode="MultiLine"></asp:textbox>
<br />
更多内容欢迎访问关中游侠的博客:<a href="http://www.0duinfo.com" title="点击访问" target="_blank">http://www.0duinfo.com</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()就可以了。
就可以搞定了
在aspx页面中onload_keydown事件中使用该函数
function text_focus() { window.form1.textbox1.focus(); }
Button1.Attributes.Add("onclick", "javascript:document.all.kongjianId.focus();")
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: