在EditorFor自动对焦 [英] Autofocus on 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
有点聪明,它根据数据类型财产。
I would like to autofocus on an editorfor in my application, but I can't seem to do that. I have successfully used autofocus on a textbox, but I would like to use an editorfor to keep my application's look universal.
Any solutions to this would be much appreciated, thank you.
My attempt:
@Html.EditorFor(model => model.Description, new { htmlAttributes = new { @class = "form-control" }, autofocus = "" })
This s because you are using EditorFor instead of something specific like TextBoxFor.
@Html.TextBoxFor(model => model.Name, new { htmlAttributes = new {
@class = "form-control" }, autofocus="autofocus"})
Or you can do that using jQuery:
<div class="editor-field focus">
@Html.EditorFor(model => model.Description)
@Html.ValidationMessageFor(model => model.Description)
</div>
$(function() {
$('.focus :input').focus();
});
Update:
As you know TextBoxFor
always creates a textbox with type input, But EditorFor
is a little bit smart, it renders markup based on the datatype of the property.
这篇关于在EditorFor自动对焦的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!