使用JQuery的textarea文本框的水印

Nic*_*ahn 3 javascript asp.net jquery

我正在尝试使用水印用于jquery的asp.net文本框控件,下面是我的代码,我看到我的textarea文本框上的标题但是当我关注或点击文本框时水印不清楚.

我从这里得到了剧本.http://www.ajaxblender.com/howto-add-hints-form-auto-focus-using-javascript.html

<asp:TextBox runat="server" ID="txtNew" class="auto-hint" title="Enter here ..." 
TextMode="MultiLine" Rows="7" Width="100%"></asp:TextBox>


<script type="text/javascript">
    $(document).ready(function () {
        // Focus auto-focus fields 
       $('.auto-focus:first').focus();

        // Initialize auto-hint fields 
        $('INPUT.auto-hint, TEXTAREA.auto-hint').focus(function () {
            if ($(this).val() == $(this).attr('title')) {
                $(this).val('');
                $(this).removeClass('auto-hint');
            }
        });

        $('INPUT.auto-hint, TEXTAREA.auto-hint').blur(function () {
            if ($(this).val() == '' && $(this).attr('title') != '') {
                $(this).val($(this).attr('title'));
                $(this).addClass('auto-hint');
            }
        });

        $('INPUT.auto-hint, TEXTAREA.auto-hint').each(function () {
            if ($(this).attr('title') == '') { return; }
            if ($(this).val() == '') { $(this).val($(this).attr('title')); }
            else { $(this).removeClass('auto-hint'); }
        });

    }); 
</script> 
Run Code Online (Sandbox Code Playgroud)

COL*_*OLD 7

如果你只是使用水印的想法,有很多选择,并有更容易的方法来实现它

1)您可以尝试使用http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/TextBoxWatermark/TextBoxWatermark.aspx

2)在HTML5中,有一个名为占位符的输入文本的新属性,它将完全按照您的意愿执行.

3)您可以使用更高级的jquery插件,这样设置起来更容易,而且不需要太多努力 http://code.google.com/p/jquery-watermark/

这里还有几个

http://wiki.jqueryui.com/w/page/12138131/Watermark

我希望它以某种方式有所帮助