forked from robvolk/jQuery.InputHints
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.inputhints.js
42 lines (35 loc) · 1.03 KB
/
jquery.inputhints.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// jQuery Input Hints plugin
// Copyright (c) 2009 Rob Volk
// http://www.robvolk.com
jQuery.fn.inputHints = function () {
function showHints(el) {
if ($(el).val() == '')
$(el).val($(el).attr('title'))
.addClass('hint');
};
function hideHints(el) {
if ($(el).val() == $(el).attr('title'))
$(el).val('')
.removeClass('hint');
};
// hides the input display text stored in the title on focus
// and sets it on blur if the user hasn't changed it.
var el = $(this);
// show the display text on empty elements
el.each(function () {
showHints(this);
});
// clear the hints on form submit
el.closest('form').submit(function () {
el.each(function () {
hideHints(this);
});
return true;
});
// hook up the blur & focus
return el.focus(function () {
hideHints(this);
}).blur(function () {
showHints(this);
});
};