作者热门文章
- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我想在我的应用程序中自动聚焦于 editorfor,但我似乎做不到。我已在文本框上成功使用自动对焦,但我想使用编辑器来保持我的应用程序的外观通用。
任何对此的解决方案将不胜感激,谢谢。
我的尝试:
@Html.EditorFor(model => model.Description, new { htmlAttributes = new { @class = "form-control" }, autofocus = "" })
最佳答案
这是因为您使用的是 EditorFor 而不是 TextBoxFor 之类的特定内容。
@Html.TextBoxFor(model => model.Name, new { htmlAttributes = new {
@class = "form-control" }, autofocus="autofocus"})
或者您可以使用 jQuery 做到这一点:
<div class="editor-field focus">
@Html.EditorFor(model => model.Description)
@Html.ValidationMessageFor(model => model.Description)
</div>
$(function() {
$('.focus :input').focus();
});
更新:
如您所知,TextBoxFor
总是创建一个带有输入类型的文本框,但是 EditorFor
有点聪明,它根据属性的数据类型呈现标记。
关于html - 自动对焦于 EditorFor,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32169014/
我是一名优秀的程序员,十分优秀!