codice:
(function($) {
$.fn.placeholder = function(options) {
var that = this;
if(!that.is('input[type=text]')) {
return;
}
var defaults = {
text: 'Placeholder'
};
options = $.extend(defaults, options);
var top = that.offset().top;
var left = that.offset().left;
return that.each(function() {
$('<span class="placeholder"/>').text(options.text).
css({
position: 'absolute',
top: top,
left: left
}).insertAfter(that);
that.focus(function() {
that.next('span.placeholder').hide();
});
that.blur(function() {
if(that.val() == '') {
that.next('span.placeholder').show();
}
});
});
};
})(jQuery);
$(function() {
$('input[name="nome"]', 'form').placeholder({text: 'Nome'});
$('input[name="email"]', 'form').placeholder({text: 'Email'});
});