Созонов Алексей

Веб-разработчик

Очищаем поле при нажатии

09.08.2015

$.fn.clearOnFocus = function(){

    /* No attribution required,
       don't use excessively */

    return this.focus(function(){
        var v = $(this).val();
        $(this).val( v === this.defaultValue ? '' : v );
    }).blur(function(){
        var v = $(this).val();
        $(this).val( v.match(/^\s+$|^$/) ? this.defaultValue : v );
    });

};

Пример:

$('input').clearOnFocus();

#JavaScript‏‎