在模糊(jQuery)上清除文本方面
-
28-09-2019 - |
题
// 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()函数的范围中定义它。
不隶属于 StackOverflow