62,046
社区成员
发帖
与我相关
我的任务
分享
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="xxx.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
</head>
<script type="text/javascript">
//设置HiddenField值
function abc(c) {
document.getElementById("HiddenField1").value = c;
}
</script>
<body>
<form id="form1" runat="server">
<!-- 这儿放一个隐藏控件 -->
<asp:HiddenField ID="HiddenField1" runat="server" />
<div>
</div>
</form>
</body>
</html>
TextBox tb = new TextBox { ID = "txtName" + i + "", Width = Unit.Parse("60px"), AutoPostBack = true};
tb.TextChanged += new System.EventHandler(tb_OnChange);
tb.Attributes.Add("onfocus", "abc('" + tb.ID + "')");
protected void tb_OnChange(object sender, EventArgs e)
{
TextBox tb = (TextBox)sender;
string name = tb.ID;
string num = name.Substring(name.Length - 1, 1);
if (HiddenField1.Value.Length > 0)
{
//通过HiddenField1.Value取得原先焦点textbox,注意,这里的Panel1是我用的容器,你按你的容器改一下
TextBox tbf = Panel1.FindControl(HiddenField1.Value) as TextBox;
tbf.Focus();
}
}
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="xxx.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
</head>
<!-- 你就贴在这儿吧 -->
<script type="text/javascript">
window.onload = function () {
document.getElementById(sessionStorage.getItem("focus")).focus();
}
function abc(c) {
sessionStorage.setItem("focus", c);
}
</script>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
<script type="text/javascript">
window.onload = function () {
document.getElementById(sessionStorage.getItem("focus")).focus();
}
function abc(c) {
sessionStorage.setItem("focus", c);
}
</script>