// Clearing Textarea
$('textarea').focus(function() {
   var $this = $(this);
   $.data(this, 'img', $this.css('background-image'));
   $this.css('background-image', 'none');
});
$('textarea').blur(function() {
    if($.trim($('textarea').val()).length){
         $this.css('background-image', 'none');
    } else {
        $(this).css('background-image', $.data(this, 'img'));
    }
});

当我单击Textarea时,尽管其中存在内容,但我仍然会看到背景图像。

谢谢你的帮助!

有帮助吗?

解决方案

增加什么 马特 说过。 $this 没有定义。你需要做的是 $(this):

$('textarea').blur(function() {
  if($.trim($('textarea').val()).length){
    // Added () around $this
    $(this).css('background-image', 'none');
  } else {
    $(this).css('background-image', $.data(this, 'img'));
  }
});

其他提示

在您的模糊功能中,您有$,但是从未定义。您仅在focus()函数的范围中定义它。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top