<fieldset>
<legend>登录表单</legend>
<ol>
<li>
<asp:Label runat="server" AssociatedControlID="UserName">用户名</asp:Label>
<asp:TextBox runat="server" ID="UserName" />
<asp:RequiredFieldValidator runat="server" ControlToValidate="UserName" CssClass="field-validation-error" ErrorMessage="用户名字段是必填字段。" />
</li>
<li>
<asp:Label runat="server" AssociatedControlID="UserName">用户名</asp:Label>
<asp:TextBox runat="server" ID="TextBox1" />
<asp:RequiredFieldValidator runat="server" ControlToValidate="UserName" CssClass="field-validation-error" ErrorMessage="用户名字段是必填字段。" />
</li>
<li>
<asp:Label runat="server" AssociatedControlID="UserName">用户名</asp:Label>
<asp:TextBox runat="server" ID="TextBox2" />
<asp:RequiredFieldValidator runat="server" ControlToValidate="UserName" CssClass="field-validation-error" ErrorMessage="用户名字段是必填字段。" />
</li>
<li>
<asp:Label runat="server" AssociatedControlID="UserName">用户名</asp:Label>
<asp:TextBox runat="server" ID="TextBox3" />
<asp:RequiredFieldValidator runat="server" ControlToValidate="UserName" CssClass="field-validation-error" ErrorMessage="用户名字段是必填字段。" />
</li>
<li>
<asp:Label runat="server" AssociatedControlID="UserName">用户名</asp:Label>
<asp:TextBox runat="server" ID="TextBox4" />
<asp:RequiredFieldValidator runat="server" ControlToValidate="UserName" CssClass="field-validation-error" ErrorMessage="用户名字段是必填字段。" />
</li>
<li>
<asp:Label runat="server" AssociatedControlID="UserName">用户名</asp:Label>
<asp:TextBox runat="server" ID="TextBox5" />
<asp:RequiredFieldValidator runat="server" ControlToValidate="UserName" CssClass="field-validation-error" ErrorMessage="用户名字段是必填字段。" />
</li>
<li>
<asp:Label runat="server" AssociatedControlID="UserName">用户名</asp:Label>
<asp:TextBox runat="server" ID="TextBox6" />
<asp:RequiredFieldValidator runat="server" ControlToValidate="UserName" CssClass="field-validation-error" ErrorMessage="用户名字段是必填字段。" />
</li>
<li>
<asp:Label runat="server" AssociatedControlID="UserName">用户名</asp:Label>
<asp:TextBox runat="server" ID="TextBox7" />
<asp:RequiredFieldValidator runat="server" ControlToValidate="UserName" CssClass="field-validation-error" ErrorMessage="用户名字段是必填字段。" />
</li>
<li>
<asp:Label runat="server" AssociatedControlID="UserName">用户名</asp:Label>
<asp:TextBox runat="server" ID="TextBox8" />
<asp:RequiredFieldValidator runat="server" ControlToValidate="UserName" CssClass="field-validation-error" ErrorMessage="用户名字段是必填字段。" />
</li>
<li>
<asp:Label runat="server" AssociatedControlID="Password">密码</asp:Label>
<asp:TextBox runat="server" ID="Password" TextMode="Password" />
<asp:RequiredFieldValidator runat="server" ControlToValidate="Password" CssClass="field-validation-error" ErrorMessage="密码字段是必填字段。" />
</li>
<li>
<asp:CheckBox runat="server" ID="RememberMe" />
<asp:Label runat="server" AssociatedControlID="RememberMe" CssClass="checkbox">记住我?</asp:Label>
</li>
</ol>
<asp:Button runat="server" CommandName="Login" Text="登录" />
</fieldset>
<script type="text/javascript">
$(function () {
var i = 0;//索引
//以上的表单位置和上下文之间的关系就是label 后面总会有一个input 标签type 可能是Password 可能是text 或者是其他的
//可以按照个人需求修改,这里只定位到type="text" 的表单如果是又有表单的话改成 $("label+ input") 即可按个人需求
$("label+ :text").each(function () {
$(this).keydown(function (e) {
if (e.keyCode == 13) {
i++;//下一个定位的索引
try {
$("label+ :text")[i].focus();
} catch (e) {//到了最后一个的下一个可能找不到元素会出现异常通过try 捕捉不至于程序出现异常
return false;//必须要写以免错误信息被提交
}
return false;//必须要写以免错误信息被提交
}
});
});
});
</script>