某一时候,为文本框(TextBox)装饰个水印。它有两种状态,一是blur和focus。因此,我们可以在Javascript写两个事件:

View Code
 1 <script type="text/javascript">
 2         var watermarkText = "输入名称";
 3 
 4         function WaterMarkOnBlur(textbox) {
 5             if (textbox.value.length == 0) {
 6                 textbox.style.color = "gray";
 7                 textbox.value = watermarkText;
 8             }            
 9         }
10 
11         function WaterMartOnfocus(textbox)
12         {
13             if (textbox.value == watermarkText) {
14                 textbox.style.color = "black";
15                 textbox.value = "";
16             }
17         }
18     </script>


在TextBox应用这两个Javascript事件:

View Code
1 <asp:TextBox ID="TextBox1" runat="server" Text="输入名称"
2                 ForeColor="Gray" onblur="WaterMarkOnBlur(this);"
3                 onfocus="WaterMartOnfocus(this);">
4             </asp:TextBox>


演示:

为TextBox装饰水印 

 

 

相关文章:

  • 2021-07-26
  • 2021-10-21
  • 2022-01-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-27
  • 2022-02-24
  • 2021-06-21
猜你喜欢
  • 2021-08-08
  • 2021-12-17
  • 2022-03-03
  • 2021-07-29
  • 2022-12-23
相关资源
相似解决方案