jQuery TextBox Water Mark with asp.net

本文转自:http://naspinski.net/post/jQuery-TextBox-Water-Mark-with-aspnet.aspx

 

I stole majority of this code from

http://www.aspcode.net/A-watermark-texbox-with-JQuery-and-aspnet.aspx

but I added a bit to make it swap css classes as well

 

$().ready(function() {
   swapValues = [];
   $(".wm").each(function(i) {
     swapValues[i] = $(this).val();
     $(this).focus(function() {
       if ($(this).val() == swapValues[i]) {
         $(this).val("").removeClass("watermark")

       } 
    }).blur(function() { 
        if ($.trim($(this).val()) == "") { $(this).val(swapValues[i]).addClass("watermark") } }) })
 }); 


To use it, make sure your TextBox has (one of) its css classes set to "wm". If you want a seperate style to be applied add that initially as well, in my example, it swaps "watermark" in and out as a css class.
 

<asp:TextBox ID="txt" runat="server"
   Text="this is the watermark" CssClass="wm watermark" /> 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。