加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

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

发布时间:2020-12-15 23:31:15 所属栏目:asp.Net 来源:网络整理
导读:在 Html 5中,文本框上有一个新的属性,称为autofocus. 问题是它是一个布尔值(有或没有) 它应该看起来像: input name="a" value="" autofocus 我试过了 : %= Html.TextBox( "a",null,new { autofocus } ) % 但是,它给我一个错误,因为我没有设置一个值来自动
在 Html 5中,文本框上有一个新的属性,称为autofocus.

问题是它是一个布尔值(有或没有)

它应该看起来像:

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

我试过了 :

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

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

我知道我可以手动做,但可以用Html.TextBox吗?

解决方法

尝试<%= Html.TextBox(“a”,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”>

应该是有效的

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读