0
// 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'));
    }
});

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

谢谢你的帮助!

4

2 回答 2

3

在你的模糊函数中,你有 $this,但它从未被定义。您只在 focus() 函数的范围内定义了它。

于 2010-06-21T14:41:45.787 回答
2

补充马特所说的。$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'));
  }
});
于 2010-06-21T14:44:13.790 回答