gpt4 book ai didi

html - 自动对焦于 EditorFor

转载 作者:太空狗 更新时间:2023-10-29 13:35:05 26 4
gpt4 key购买 nike

我想在我的应用程序中自动聚焦于 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com