Asp.Net的mvc - Html.TextBox - 设置自动对焦性能 [英] Asp.Net Mvc - Html.TextBox - Set Autofocus property

查看:186
本文介绍了Asp.Net的mvc - Html.TextBox - 设置自动对焦性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在HTML 5中,没有对文本框被称为自动聚焦一个新的属性。

In Html 5, there is a new attribute on textbox called autofocus.

现在的问题是,它是一个布尔值(有或不存在)

The problem is that it is a boolean value (there or not there)

这应该是这个样子:

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

我想:

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

不过,它给了我一个错误,因为我没有设定值自动对焦...

But, it gives me an error because I'm not setting a value to autofocus...

我知道我可以做手工,但我可以做它Html.TextBox?

I know I can do it manually, but can I do it with Html.TextBox ?

推荐答案

尝试&LT;%= Html.TextBox(A,空,新{自动对焦=})%&GT;

据布尔属性 HTML5规范的:

如果该属性为present,其值必须要么是在空字符串或一个值,该值是一个ASCII不区分大小写匹配的属性的规范名称 ,没有开头或结尾的空白。

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.

因此​​,无论

  • &LT;输入名称=a值=自动对焦&GT;
  • &LT;输入名称=a值=自动对焦=&GT;
  • &LT;输入名称=a值=自动对焦=自动对焦&GT;
  • <input name="a" value="" autofocus> or
  • <input name="a" value="" autofocus=""> or
  • <input name="a" value="" autofocus="autofocus">

应该是有效的。

这篇关于Asp.Net的mvc - Html.TextBox - 设置自动对焦性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆