无需使用JavaScript,即可将注意力集中在EditorFor [英] Set focus on an EditorFor without the use of JavaScript
本文介绍了无需使用JavaScript,即可将注意力集中在EditorFor的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以在不使用JavaScript的情况下将重点放在页面加载时的以下代码上?
Is it possible to set the focus on the following code on a page load without the use of JavaScript?
<div class="col-md-10">
@Html.EditorFor(model => model.Description)
@Html.ValidationMessageFor(model => model.Description)
</div>
推荐答案
您可以使用autofocus
属性. 参考文档
@Html.TextBoxFor(model => model.Description, new { autofocus = "autofocus" })
EditorFor
的等效项(仅使用MVC-5.1 +)通过以下语法获得:
The equivalent for EditorFor
(using MVC-5.1+ only) is obtained with the following syntax:
@Html.EditorFor(model => model.Description, new { htmlAttributes = new { autofocus = "autofocus" } })
这篇关于无需使用JavaScript,即可将注意力集中在EditorFor的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文