开发者

Jquery plugin for this effect? and what is the effect called?

I've implemented this effect myself several times in raw jquery code, but I want to have it as a plugin. Problem is I don't know what it's called to search for the plugin. Basically, the input field has its label in pale gray inside the field itself. When the user clicks, the gray label disappears. If the user exited the field without typing anything, the gray label returns. Otherwise, whatever the user types stays ther开发者_如何学编程e. It's really simple, does it have a name, and is there a plugin for it so I could something like

$('#blabla').effectname('Label'); 

Sorry if this is a stupid question but I'm really blanking out on this one.


It sounds like you're describing a 'placeholder'. This is actually built into HTML 5, and is supported in (as of this writing) WebKit (Chrome + Safari), FireFox 3.7 and above, and IE 9 beta (I think).

Just doing a bit of searching around I found this jQuery plugin - jQuery Placeholder.


Here is one I wrote a long time ago, I am sure it will help.

The function:

function textReplacement(input) {
    var originalvalue = input.val();
    input.focus(function() {
        if ($.trim(input.val()) == originalvalue) {
            input.val('').css("color", "#000");
        }
    });
    input.blur(function() {
        if ($.trim(input.val()) == '') {
            input.val(originalvalue).css("color", "#999");
        }
    });
}

The usage:

textReplacement($('input#thisID').css("color", "#999"));

Enjoy!


It's called a watermark or placeholder. There is a suitable jQuery plugin I've used with no complaints here. It has all sorts of good stuff (like drag-and-drop support!).

I'm sure you can find many others as well. http://www.google.com/search?q=jQuery+watermark

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜