【问题标题】:How to set focus on first field of input in BootStrap? [duplicate]如何在 BootStrap 中的第一个输入字段上设置焦点? [复制]
【发布时间】:2015-11-10 10:11:22
【问题描述】:

可能重复:
How to set the focus to the first input element in an HTML form independent from the id?

我正在使用带有 ASP.NET MVC4 的 BootStrap。有一个登录表单,但我无法将焦点设置在第一个输入字段上。

如何将焦点设置在输入的第一个字段上?是否有任何用于设置焦点的 BootStrap 类?

【问题讨论】:

  • @Richard :您提到的重复问题中缺少 BootStrap。
  • 这个问题不是 bootstrap 特有的。无论您是否使用引导程序,解决方案都是相同的。

标签: javascript html twitter-bootstrap


【解决方案1】:

没有特定于 Bootstrap 的类或函数可以执行此操作*,但 HTML5 为输入字段提供了the autofocus attribute

This attribute currently enjoys wide browser support.

*-由于您使用的是 Bootsrap,并且 Bootstrap 由 jQuery 提供支持,因此您可以“填充”不支持自动对焦的旧浏览器:

$('[autofocus]:first').focus();

【讨论】:

  • 嗯,我的答案几乎与 Q/A @Richard 参考的答案相同。原创内容:失败。
  • 虽然共识是很好的强化。
  • 提示:如果您有 Modernizr,您可以使用 Modernizr.input.autofocus (
猜你喜欢
  • 2018-04-16
  • 2021-03-18
  • 1970-01-01
  • 1970-01-01
  • 2020-11-05
  • 1970-01-01
  • 2016-12-24
  • 1970-01-01
相关资源
最近更新 更多