2017-02-13 27 views
-1
<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 = "[email protected]", @name = "txtemailaddress" }) 
         @Html.ValidationMessageFor(i => i.EmailAddress, "", new { @class = "error" }) 
        </div> 

在我的代碼我這樣做:如何設置側重於在頁面加載「系名稱」文本框中以下剃刀代碼

$(document).ready(function() {  
    $(".form:first").focus(); 
}); 
+0

更好地利用'$( '形式控制]名稱= 「txtfacultyname」]。')聚焦(); –

回答

0

你可以在註釋,如果使用@Tariq選項你只是想第一個輸入:

$(function() {  
    $(".form input:first").focus(); 
}); 

甚至目標formcontrol

$(function() {  
    $(".form .form-control:first").focus(); 
}); 
0

「Faculty Name」文本框的類名是form-control而不是form。所以使用該選擇器來關注它。

$(document).ready(function() { 
$(".form-control:first").focus(); 
});` 
0
$('.form-control[name="txtfacultyname"]').focus(); 

或第一輸入

$('.form-control input:first').focus(); 
相關問題