Хабр Курсы для всех
РЕКЛАМА
Практикум, Хекслет, SkyPro, авторские курсы — собрали всех и попросили скидки. Осталось выбрать!
(function($) {
$.fn.watermark = function() {
this.each(function() {
new WatermarkField(this);
});
function WatermarkField(input) {
var self = this;
this.input = input;
this.label = $('label[for="' + this.input.id + '"]')[0];
var div = document.createElement('div');
$(div).css({ 'position': 'relative' });
$(this.input).wrap(div);
$(this.input.parentNode).append(self.label);
$(self.label).css({
'position': 'absolute',
'z-index': '10',
'left': '3px',
'top': '0px',
'opacity': '0.5'
});
$(this.input).bind("change", function() { self.Update() });
$(this.input).bind("blur", function() { self.Update(); });
if ($.browser.opera) {
$(this.input).bind("keypress", function() {
setTimeout(function() { self.Update() }, 0);
});
} else {
$(this.input).bind("keydown", function() {
setTimeout(function() { self.Update() }, 0);
});
}
}
WatermarkField.prototype.Update = function() {
if (this.input.value != "") {
$(this.label).css({ 'visibility': 'hidden' });
} else if (this.input.value == "") {
$(this.label).css({ 'visibility': 'visible' });
}
}
}
})(jQuery);
* This source code was highlighted with Source Code Highlighter. $(function() {
$('.watermark').watermark();
});
Подборка плагинов к jQuery