标签:
某一时候,为文本框(TextBox)装饰个水印。它有两种状态,一是blur和focus。因此,我们可以在Javascript写两个事件:
<script type="text/javascript"> var watermarkText = "输入名称"; function WaterMarkOnBlur(textbox) { if (textbox.value.length == 0) { textbox.style.color = "gray"; textbox.value = watermarkText; } } function WaterMartOnfocus(textbox) { if (textbox.value == watermarkText) { textbox.style.color = "black"; textbox.value = ""; } } </script>
<asp:TextBox ID="TextBox1" runat="server" Text="输入名称" 2 ForeColor="Gray" onblur="WaterMarkOnBlur(this);" 3 onfocus="WaterMartOnfocus(this);"> 4 </asp:TextBox>
演示:
标签:
原文地址:http://www.cnblogs.com/shouce/p/5277944.html