登录页面打开后如何将光标聚焦在用户名文本框上 [英] How to focus cursor on Username textbox once open logon page
本文介绍了登录页面打开后如何将光标聚焦在用户名文本框上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
一旦用户在此页面内输入光标,便拥有登录页面,必须是用户名"文本框
如何关注这个问题.
正在使用MVC3,并希望使用jQuery
做到这一点
请任何人帮助
Am having logon page once user enter inside this page cursor must be Username Text box
How to focus this .
am using MVC3 and would like to do this with jQuery
please anyone help
推荐答案
看看这个:
如何将焦点设置为一个文本框Html.TextBoxFor-mvc 2 [
Take a look at this:
How do I set focus to a text box Html.TextBoxFor - mvc 2[^]
or try this:
@model MvcApplication1.Models.LogOnModel
@{
ViewBag.Title = "Log On";
}
<script type="text/javascript">
(function () {
(function () {
(''#txtUserName'').focus(); }); </script> <h2>Log On</h2> <p> Please enter your user name and password. @Html.ActionLink("Register", "Register") if you don''t have an account. </p> <script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script> <script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script> @Html.ValidationSummary(true, "Login was unsuccessful. Please correct the errors and try again.") @using (Html.BeginForm()) { <div> <fieldset> <legend>Account Information</legend> <div class="editor-label"> @Html.LabelFor(m => m.UserName) </div> <div class="editor-field"> @Html.TextBoxFor(m => m.UserName, new { maxlength = 23, id = "txtUserName"}) @Html.ValidationMessageFor(m => m.UserName) </div> <div class="editor-label"> @Html.LabelFor(m => m.Password) </div> <div class="editor-field"> @Html.PasswordFor(m => m.Password) @Html.ValidationMessageFor(m => m.Password) </div> <div class="editor-label"> @Html.CheckBoxFor(m => m.RememberMe) @Html.LabelFor(m => m.RememberMe) </div> <p> <input type="submit" value="Log On" /> </p> </fieldset> </div> }
(''#txtUserName'').focus(); }); </script> <h2>Log On</h2> <p> Please enter your user name and password. @Html.ActionLink("Register", "Register") if you don''t have an account. </p> <script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script> <script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script> @Html.ValidationSummary(true, "Login was unsuccessful. Please correct the errors and try again.") @using (Html.BeginForm()) { <div> <fieldset> <legend>Account Information</legend> <div class="editor-label"> @Html.LabelFor(m => m.UserName) </div> <div class="editor-field"> @Html.TextBoxFor(m => m.UserName, new { maxlength = 23, id = "txtUserName"}) @Html.ValidationMessageFor(m => m.UserName) </div> <div class="editor-label"> @Html.LabelFor(m => m.Password) </div> <div class="editor-field"> @Html.PasswordFor(m => m.Password) @Html.ValidationMessageFor(m => m.Password) </div> <div class="editor-label"> @Html.CheckBoxFor(m => m.RememberMe) @Html.LabelFor(m => m.RememberMe) </div> <p> <input type="submit" value="Log On" /> </p> </fieldset> </div> }
它已经过测试并可以正常工作.
It has been tested and works.
这篇关于登录页面打开后如何将光标聚焦在用户名文本框上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文