What should I call this behavior?
I'm looking to make a simple jquery plugin. It would typically be called o开发者_运维问答n textboxes/textareas, its job would be to clear the textbox of all text when focus is put there, and fill it back with what it had previously when focus is taken away.
E.g I have a textbox for the user's name. By default it says : 'First Name'. I want to have that cleared away if i click/focus in that textbox, but when I focus away, I want it to say 'first name' again.
What should I call this plugin? I'd probably use it like this:
$("#myTextbox").pluginName();
PrimeFaces calls it watermark. HTML5 calls it placeholder.
You are hiding some text, so call it something like hideXText().
hidetoggleExampleText()
hide`toggleTip()
hide`toggleHintText()
hide`toggleHint
Why bother when there are a heap that already do this for you?
here are a few
In HTML5 forms it's called the placeholder attribute, so maybe something like that to indicate what it does.
$(":text").focus(function(lp) {
var p_val = "DefaultText";
if ($(this).val() == p_val) {
$(this).val("");
}
});
$(":text").blur(function() {
var p_val = "DefaultText";
if ($(this).val() == "") {
$(this).val(p_val);
}
});
$(":text").blur();
精彩评论