【发布时间】:2011-03-11 00:23:51
【问题描述】:
请看这个 jsFiddle:https://jsfiddle.net/Wmq6f/
我有一个带有背景图像的文本区域,它在“焦点”时被删除并在“模糊”时恢复,但是当文本区域中存在内容时,它不应该在任何一种情况下显示,但我无法实现使用这个 jQuery:
$('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'));
}
});
感谢您的帮助
【问题讨论】:
标签: jquery focus background textarea