gpt4 book ai didi

asp.net-mvc - Asp.Net Mvc - Html.TextBox - 设置自动对焦属性

转载 作者:行者123 更新时间:2023-12-03 02:24:10 25 4
gpt4 key购买 nike

在 Html 5 中,文本框上有一个名为 autofocus 的新属性。

问题在于它是一个 bool 值(存在或不存在)

它应该看起来像:

<input name="a" value="" autofocus>

我尝试过:

<%= Html.TextBox( "a", null, new { autofocus } ) %>

但是,它给了我一个错误,因为我没有设置自动对焦的值......

我知道我可以手动完成,但是我可以使用 Html.TextBox 完成吗?

最佳答案

尝试<%= Html.TextBox( "a", null, new { autofocus = "" } ) %>

根据HTML5 spec on boolean attributes :

If the attribute is present, its value must either be the empty string or a value that is an ASCII case-insensitive match for the attribute's canonical name, with no leading or trailing whitespace.

所以要么

  • <input name="a" value="" autofocus>
  • <input name="a" value="" autofocus="">
  • <input name="a" value="" autofocus="autofocus">

应该是有效的。

关于asp.net-mvc - Asp.Net Mvc - Html.TextBox - 设置自动对焦属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2998247/

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