如何使文本框readOnly的 [英] How to make textbox readOnly

查看:112
本文介绍了如何使文本框readOnly的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何使这个只读文本框和里面显示为灰色文字?

 <%= Html.TextBox(名称)%GT;


解决方案

如果您还没有一个初始值可以同时只提供属性匿名对象设置为

相关属性

 <%= Html.TextBox(名,空,新的{@ReadOnly =真})%GT;
<! - 或 - >
<%= Html.TextBox(名,空,新的{@ReadOnly =只读})%GT;

如果你有一个值来设置该文本框中这两个应该是

 <%= Html.TextBox(名,一些文本框的值,新{@ReadOnly =真})%GT;
<! - 或 - >
<%= Html.TextBox(名,一些文本框的值,新{@ReadOnly =只读})%GT;

问题是,这样的属性为只读隐藏应该没有任何值被设置(根据规范) ,但可以使用标准的 HTML helper方法不能提供这样的属性。好事是,虽然你可以设置任何一个值。但是可读性的缘故,使他们有意义,最好他们要么设置为真正或属性名称如在我的例子。

How do I make this a readOnly textBox, and the text inside it appear as gray?

<%=  Html.TextBox("name")%>

解决方案

If you don't have an initial value you can as well provide only attributes anonymous object with relevant attribute set as

<%=  Html.TextBox("name", null, new { @readonly = true })%>
<!-- or -->
<%=  Html.TextBox("name", null, new { @readonly = "readonly" })%>

If you do have a value to set to this text box these two should be

<%=  Html.TextBox("name", "Some textbox value", new { @readonly = true })%>
<!-- or -->
<%=  Html.TextBox("name", "Some textbox value", new { @readonly = "readonly" })%>

The thing is that such attributes as readonly or hidden should be set without any value (according to specification), but you can't provide such attributes using standard Html helper methods. The good thing though is that you can set anything as a value. But for the sake of readability and making them meaningful it's best to set them either to true or attribute name as shown in my example.

这篇关于如何使文本框readOnly的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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