html – 在EditorFor上自动对焦

html – 在EditorFor上自动对焦,第1张

概述我想在我的应用程序中自动聚焦编辑器,但我似乎无法做到这一点.我已成功在文本框上使用自动对焦,但我想使用编辑器来保持应用程序的外观普遍. 任何解决方案都将非常感谢,谢谢. 我的尝试: @Html.EditorFor(model => model.Description, new { htmlAttributes = new { @class = "form-control" }, autofocus 我想在我的应用程序中自动聚焦编辑器,但我似乎无法做到这一点.我已成功在文本框上使用自动对焦,但我想使用编辑器来保持应用程序的外观普遍.

任何解决方案都将非常感谢,谢谢.

我的尝试:

@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 >    @HTML.EditorFor(model => model.Description)    @HTML.ValIDationMessageFor(model => model.Description)</div> $(function() {    $('.focus :input').focus();});

更新:如你所知,TextBoxFor总是创建一个带有类型输入的文本框,但是EditorFor有点聪明,它会根据属性的数据类型呈现标记.

总结

以上是内存溢出为你收集整理的html – 在EditorFor上自动对焦全部内容,希望文章能够帮你解决html – 在EditorFor上自动对焦所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://www.outofmemory.cn/web/1137830.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存