jQuery размытие не работает - PullRequest
0 голосов
/ 02 декабря 2011

Функция jQuery blur() отказывается работать. Хотя входное значение сохраняется, оно не отображается. Кто-нибудь может сказать мне, почему? Я также попробовал on('blur', function(){}); без удачи.

$('form').each(function() {
    $(this).find(':input')
        .not('input[type=submit], input[type=hidden]')
        .each(function() {

        if (!($.trim($(this).val()))) {
            if ($(this).attr('data-placeholder')) {
                putPlaceholder(this);
            }
        }
        $(this).blur(function() {
            if (!($.trim($(this).val()))) {
                putPlaceholder(this);
            }
        });
    });
});

1 Ответ

0 голосов
/ 02 декабря 2011

У меня все отлично работает здесь: http://jsfiddle.net/mmmshuddup/aswXV/3/

var placeholder = "I'm a placeholder";
function putPlaceholder(el) {
    // do something
    el.value = placeholder;
    $(el).addClass('placeholder');
}

$('form').each(function() {
    $(this).find(':input')
        .not('input[type=submit], input[type=hidden]')
        .each(function() {
        if (!$.trim(this.value)) {
            if ($(this).attr('data-placeholder')) {
                putPlaceholder(this);
            }
        }

        $(this).focus(function() {
            if (this.value == placeholder) {
                this.value = '';
            }
            $(this).removeClass('placeholder');
        }).blur(function() {
            if (!$.trim(this.value)) {
                putPlaceholder(this);
            }
        });
    });
});
...