Autofocs无法在Chrome

问题描述:

工作,我写在我看来,这条线在今年年初Autofocs无法在Chrome

@Html.EditorFor(x => x.ItemID, new { htmlAttributes = new { autofocus = "autofocus" } }) 

它好工作在两个Firefox和Chrome浏览器设置自动对焦到该领域。我最近重新浏览了此页面,发现Chrome上不再设置自动对焦。它仍然适用于Firefox。

关于如何修改此代码以使其重新运行的任何想法。也许有一些Chrome扩展可以用来代替

您可以使用autofocus属性。 Refer documentation

@Html.TextBoxFor(model => model.Description, new { autofocus = "autofocus" }) 

的等效EditorFor(使用MVC-5.1 +只)与下面的语法获得:

@Html.EditorFor(model => model.Description, new { htmlAttributes = new { autofocus = "autofocus" } }) 

或者你也可以做到这一点使用jQuery:

<div class="editor-field focus"> 
    @Html.EditorFor(model => model.Description) 
    @Html.ValidationMessageFor(model => model.Description) 
</div> 
$(function() { 
    $('.focus :input').focus(); 
});