ASP .NET - TextBox ¿Ø¼þ
TextBox ¿Ø¼þÓÃÓÚ´´½¨Óû§¿ÉÊäÈëÎı¾µÄÎı¾¿ò¡£
TextBox ¿Ø¼þ
TextBox ¿Ø¼þÓÃÓÚ´´½¨Óû§¿ÉÊäÈëÎı¾µÄÎı¾¿ò¡£
TextBox ¿Ø¼þµÄÊôÐÔÁÐÔÚÎÒÃÇµÄ TextBox ¿Ø¼þ²Î¿¼ÊÖ²áÖС£
ÏÂÃæµÄÀý×ÓÑÝʾÁËÄú¿ÉÄÜÔÚ TextBox ¿Ø¼þÖÐʹÓõ½µÄһЩÊôÐÔ£º
<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>
Ìí¼Ó½Å±¾
µ±±íµ¥±»Ìύʱ£¬TextBox ¿Ø¼þµÄÄÚÈݺÍÉèÖÿÉͨ¹ý·þÎñÆ÷½Å±¾½øÐÐÐ޸ġ£¿Éͨ¹ýµã»÷Ò»¸ö°´Å¥»òµ±Óû§¸ü¸Ä TextBox ¿Ø¼þÖеÄÖµ¶Ô±íµ¥½øÐÐÌá½»¡£
ÔÚÏÂÃæµÄÀý×ÓÖУ¬ÎÒÃÇÔÚÒ»¸ö .aspx ÎļþÖÐÉùÃ÷ÁËÒ»¸ö TextBox ¿Ø¼þ¡¢Ò»¸ö Button ¿Ø¼þºÍÒ»¸ö Label ¿Ø¼þ¡£µ±Ìá½»°´Å¥±»´¥·¢Ê±£¬submit ×ÓÀý³Ì¾Í»á±»Ö´ÐС£submit ×ÓÀý³Ì»áÏò Label ¿Ø¼þдһÌõÎı¾£º
<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>
ÔÚÏÂÃæµÄÀý×ÓÖУ¬ÎÒÃÇÔÚÒ»¸ö .aspx ÎļþÖÐÉùÃ÷ÁËÒ»¸ö TextBox ¿Ø¼þºÍÒ»¸ö Label ¿Ø¼þ¡£µ±Äú¸ü¸ÄÁË TextBox ÖеÄÖµ£¬²¢ÇÒÔÚ TextBox Íâµ¥»÷ʱ£¬change ×ÓÀý³Ì¾Í»á±»Ö´ÐС£change ×ÓÀý³Ì»áÏò Label ¿Ø¼þдһÌõÎı¾£º
<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>