如何将重点放在"FacultyName"上以下Razor代码在页面加载中的文本框 [英] How can I set focus on "FacultyName" textbox on page load for the following Razor code

查看:54
本文介绍了如何将重点放在"FacultyName"上以下Razor代码在页面加载中的文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<div class="form-group">
    <label>Faculty Name *</label>
    @Html.TextBoxFor(i => i.FacultyName, new { @class = "form-control", @placeholder = "Technician e.t.c", @name = "txtfacultyname" })
    @Html.ValidationMessageFor(i => i.FacultyName, "", new { @class = "error" })
</div>
<div class="form-group">
     <label>EmailAddress *</label>
     @Html.TextBoxFor(i => i.EmailAddress, new { @class = "form-control", @placeholder = "abc@abc.com", @name = "txtemailaddress" })
     @Html.ValidationMessageFor(i => i.EmailAddress, "", new { @class = "error" })
</div>
<div class="form-group">
     <label>User Name *</label>
     @Html.TextBoxFor(i => i.UserName, new { @class = "form-control", @placeholder = "abc e.t.c", @name = "txtusername" })
     @Html.ValidationMessageFor(i => i.UserName, "", new { @class = "error" })
</div>

推荐答案

您可以使用$('#FacultyName').focus()

我稍微更改了您的代码只是为了向您展示它的工作原理.

I changed your code a bit just to show you that it works.

$(document).ready(function() {
  $('#FacultyName').focus() // This code will only run when the page is done loading/ready
})

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="form-group">
  <label>Faculty Name *</label>
  <input id="FacultyName"></input>
</div>
<div class="form-group">
  <label>EmailAddress *</label>
  <input id="EmailAddress"></input>
</div>
<div class="form-group">
  <label>User Name *</label>
  <input id="UserName"></input>
</div>

这篇关于如何将重点放在"FacultyName"上以下Razor代码在页面加载中的文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆