用户的文本框中的占位符/示例文本

时间:2023-02-04 00:57:49

What is the step to get example text to show up in an asp.net textbox.

将示例文本显示在asp.net文本框中的步骤是什么?

For example, textbox w/ ID = "textboxDate" has [mm/dd/yyyy] inside it for the user to reference.

例如,文本框w / ID =“textboxDate”内部有[mm / dd / yyyy]供用户引用。

4 个解决方案

#1


37  

I believe you want a placeholder attribute:

我相信你想要一个占位符属性:

<asp:TextBox ID="placeholderTextBox" runat="server" placeholder="mm/dd/yyyy"></asp:TextBox>

#2


6  

but placeholder doenst work for many IE browser because placeholder is html5 thing.

但占位符doenst为许多IE浏览器工作,因为占位符是html5的东西。

try to use modernizr framework. it works for all browsers including all IE

尝试使用modernizr框架。它适用于所有浏览器,包括所有IE

here is a sample code for you.

这是一个示例代码。

if(modernizr.input.placeholder) {
   //insert placeholder polyfill script here. 
}

#3


1  

Visual Studio maybe not knowing the attribute. Attributes which are not registered with ASP.net are passed through and rendered as is.

Visual Studio可能不知道该属性。未在ASP.net中注册的属性将按原样传递和呈现。

<asp:TextBox ID="TextBox1" runat="server"  Width="187px" placeholder="mm/dd/yyyy"></asp:TextBox>

So the above code (basically) renders to:

所以上面的代码(基本上)呈现给:

<input type="text" placeholder="mm/dd/yyyy"/>

#4


1  

You can allways use:

你总是可以使用:

<input ID="placeholderTextBox" type="text" runat="server" placeholder="mm/dd/yyyy" />

and on code behind you can get or set the value using

在后面的代码中,您可以使用获取或设置值

Dim myValue As String = placeholderTextBox.value or placeholderTextBox.value = "whatsoever"

#1


37  

I believe you want a placeholder attribute:

我相信你想要一个占位符属性:

<asp:TextBox ID="placeholderTextBox" runat="server" placeholder="mm/dd/yyyy"></asp:TextBox>

#2


6  

but placeholder doenst work for many IE browser because placeholder is html5 thing.

但占位符doenst为许多IE浏览器工作,因为占位符是html5的东西。

try to use modernizr framework. it works for all browsers including all IE

尝试使用modernizr框架。它适用于所有浏览器,包括所有IE

here is a sample code for you.

这是一个示例代码。

if(modernizr.input.placeholder) {
   //insert placeholder polyfill script here. 
}

#3


1  

Visual Studio maybe not knowing the attribute. Attributes which are not registered with ASP.net are passed through and rendered as is.

Visual Studio可能不知道该属性。未在ASP.net中注册的属性将按原样传递和呈现。

<asp:TextBox ID="TextBox1" runat="server"  Width="187px" placeholder="mm/dd/yyyy"></asp:TextBox>

So the above code (basically) renders to:

所以上面的代码(基本上)呈现给:

<input type="text" placeholder="mm/dd/yyyy"/>

#4


1  

You can allways use:

你总是可以使用:

<input ID="placeholderTextBox" type="text" runat="server" placeholder="mm/dd/yyyy" />

and on code behind you can get or set the value using

在后面的代码中,您可以使用获取或设置值

Dim myValue As String = placeholderTextBox.value or placeholderTextBox.value = "whatsoever"