【问题标题】:How can I show formatted text in textarea, if it is empty?如果文本区域为空,如何在文本区域中显示格式化文本?
【发布时间】:2012-02-03 12:42:11
【问题描述】:

如何在失去焦点后使用 jQuery(使用 ul li p...)显示文本,并且 textarea 为空,现在当我获得焦点时,我失去了文本,但是如果我没有如何显示它输入了什么? 我的“伪占位符”如下所示:

$('textarea.hinted').focus(function() {
    console.log('focus');
    $('#textarea-placeholder').hide();
});
$('textarea.hinted').blur(function() {
    console.log('blur');
    $('#textarea-placeholder').hide();
});
$('textarea.hinted').focusout(function() {
    console.log($(this).val());
    if (this.val == '') {
        $('#textarea-placeholder').show(); 
    }
});

html

【问题讨论】:

  • 标题很混乱。如果没有内容,为什么要格式化任何内容?
  • 我在这里的理解是你想在 texatarea 为空时显示它的内容?目标是什么?
  • 令人困惑的问题...也许您需要搜索框之类的东西?如果您集中注意力,搜索文本会在哪里消失,如果此输入中没有任何内容,则搜索文本会再次出现?

标签: jquery haml


【解决方案1】:
$('textarea.hinted').focusout(function() {
    if ($(this).val() == '') {
        $('#textarea-placeholder').show(); 
    }
});

应该可以,

你也应该消除模糊,即使它们实际上是同一件事(我相信)

【讨论】:

    猜你喜欢
    • 2015-11-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-28
    • 1970-01-01
    相关资源
    最近更新 更多