ÍøÂçѧԺ w3popÉçÇø ÍøÂç×ÊÔ´ ITÐÂÎÅ

w3pop.com :: ÍøÂçѧԺ :: ASP.NET :: ASP.NET - TextBox(Îı¾¿ò)¿Ø¼þ

»áÔ±µÇ½

ÕʺÅ

ÃÜÂë

»Ø´ð

¼ÇסÃÜÂë

Íü¼ÇÃÜÂë? ×¢²á

ASP.NET
asp.netµÄ°²×°
ASP ºÍ ASP.NET Ö..
ASP.NET ½éÉÜ

ASP.NET - TextBox(Îı¾¿ò)¿Ø¼þ


×÷Õß:w3schools ·­Òë/ÕûÀí:w3pop.com ·¢²¼:2007-08-06 ä¯ÀÀ:3063 :: ::

The TextBox control is used to create a text box where the user can input text.
Îı¾¿ò¿Ø¼þ¿ÉÓÃÀ´´´½¨Óû§ÊäÈëÎÄ×ÖÓõÄÎı¾¿ò¡£


The TextBox Control
Îı¾¿ò¿Ø¼þ

The TextBox control's attributes and properties are listed in our web controls reference page.
ÔÚÎÒÃǵÄWEB¿Ø¼þ²Î¿¼Ò³ÖÐÂÞÁÐÁËÎı¾¿ò¿Ø¼þµÄËùÓÐÊôÐÔ¡£

The example below demonstrates some of the attributes you may use with the TextBox control:
ÏÂÃæËùÒªÑÝʾµÄÊÇÄãÔÚʹÓÃÎı¾¿ò¿Ø¼þʱ¿ÉÄÜ»áÓõ½µÄһЩÊôÐÔ£º

Example£¨¾ÙÀý£©

<html>
<body>

<form runat="server">

A basic TextBox(×î»ù±¾µÄÎı¾¿ò):
<asp:TextBox id="tb1" runat="server" />
<br /><br />

A password TextBox(ÃÜÂëģʽµÄÎı¾¿ò):
<asp:TextBox id="tb2" TextMode="password" runat="server" />
<br /><br />

A TextBox with text(´øÓÐÎÄ×ÖµÄÎı¾¿ò):
<asp:TextBox id="tb4" Text="Hello World!" runat="server" />
<br /><br />

A multiline TextBox(¶àÐÐÎı¾¿ò):
<asp:TextBox id="tb3" TextMode="multiline" runat="server" />
<br /><br />

A TextBox with height(´ø¸ß¶ÈµÄÎı¾¿ò):
<asp:TextBox id="tb6" rows="5" TextMode="multiline"
runat="server" />
<br /><br />

A TextBox with width(´ø¿í¶ÈµÄÎı¾¿ò):
<asp:TextBox id="tb5" columns="30" runat="server" />

</form>

</body>
</html>

 


Add a Script
Ìí¼Ó½Å±¾

The contents and settings of a TextBox control may be changed by server scripts when a form is submitted. A form can be submitted by clicking on a button or when a user changes the value in the TextBox control.
µ±±íµ¥±»Ìύʱ¿Éͨ¹ý·þÎñÀ´µ÷ÕûÎı¾¿òµÄÄÚÈݺÍÉ趨¡£Ò»ÕÅ±íµ¥¿Éͨ¹ýµã»÷°´Å¥»òÊǵ±Óû§¸Ä±äÎı¾¿òµÄÄÚÈÝʱ½øÐÐÌá½»¡£

In the following example we declare one TextBox control, one Button control, and one Label control in an .aspx file. When the submit button is triggered, the submit subroutine is executed. The submit subroutine writes a text to the Label control:
ÔÚÏÂÃæµÄ¾ÙÀýÖÐÎÒÃÇÔÚÒ»¸ö.aspxÎļþÖÐÉùÃ÷ÁËÒ»¸öÎı¾¿ò¿Ø¼þ£¬º¬ÓÐÒ»¸ö°´Å¥¿Ø¼þ£¬Ò»¸ö±êÇ©¿Ø¼þ¡£µ±´¥·¢ÁËÌá½»°´Å¥£¬Ìá½»µÄ×Ó³ÌÐò¸øÓèÖ´ÐС£Ìá½»µÄ×Ó³ÌÐò»áÔÚ±êÇ©¿Ø¼þÀïдÉÏһЩÎÄ×Ö£º

<script runat="server">
Sub submit(sender As Object, e As EventArgs)
lbl1.Text="Your name is " & txt1.Text
End Sub
</script>
<html>
<body>
<form runat="server">
Enter your name:
<asp:TextBox id="txt1" runat="server" />
<asp:Button OnClick="submit" Text="Submit" runat="server" />
<p><asp:Label id="lbl1" runat="server" /></p>
</form>
</body>
</html>

Example£¨¾ÙÀý£©

In the following example we declare one TextBox control and one Label control in an .aspx file. When you change the value in the TextBox and either click outside the TextBox or press the Tab key, the change subroutine is executed. The submit change subroutine writes a text to the Label control:
ÔÚÏÂÃæµÄ¾ÙÀýÖÐÎÒÃǽ«ÔÚÒ»¸ö.aspxÎļþÖÐÉùÃ÷Ò»¸öÎı¾¿ò¿Ø¼þÒÔ¼°Ò»¸ö±êÇ©¿Ø¼þ¡£µ±Äã¸Ä±äÁËÎı¾¿òµÄÄÚÈݲ¢½«½¹µãÒÆÀëÎı¾¿ò(Êó±êµãÎı¾¿òµÄÍâÃæ»òÊǰ´ÁËTab¼ü)£¬change ×Ó³ÌÐò½«¸øÓèÖ´ÐС£change×Ó³ÌÐò»áÔÚ±êÇ©¿Ø¼þÉÏдÉÏһЩÎÄ×Ö£º

<script runat="server">
Sub change(sender As Object, e As EventArgs)
lbl1.Text="You changed text to " & txt1.Text
End Sub
</script>
<html>
<body>
<form runat="server">
Enter your name:
<asp:TextBox id="txt1" runat="server"
text="Hello World!"
ontextchanged="change" autopostback="true"/>
<p><asp:Label id="lbl1" runat="server" /></p>
</form>
</body>
</html>

Example£¨¾ÙÀý£©

ÆÀÂÛ (0) All