jQuery 模糊不起作用

发布于 2024-12-19 06:54:42 字数 590 浏览 4 评论 0原文

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);
            }
        });
    });
});

jQuery's blur() function refuses to work. Although the input value gets saved, it doesn't show. Can anyone tell me why? I've also tried on('blur', function(){}); with no luck.

$('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);
            }
        });
    });
});

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

姐不稀罕 2024-12-26 06:54:42

我在这里完美运行: 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);
            }
        });
    });
});

I got it working perfectly here: 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);
            }
        });
    });
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文