切换背景图像 (jQuery)
$('textarea').focus(function() {
var img = $(this).css('background-image');
$(this).css('background-image', 'none');
});
$('textarea').blur(function() {
$(this).css('background-image', img);
});
..似乎不起作用。我觉得有些不对劲,但又想不出来到底是什么。
非常感谢您的帮助!
$('textarea').focus(function() {
var img = $(this).css('background-image');
$(this).css('background-image', 'none');
});
$('textarea').blur(function() {
$(this).css('background-image', img);
});
.. doesn't seem to work. I think somethings wrong, but I can't figure out what.
Many thanks for your help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您仅在
.focus()
事件处理程序中定义,则该变量将在以下范围内不可用
.blur()
因此,要么全局定义
var img
,要么使用 jQuery 的.data()
方法。写:
读:
示例:
If you define
just inside the
.focus()
event handler, that variable will not be available within.blur()
So either define
var img
globaly, or use jQuerys.data()
method for instance.write:
read:
example:
尝试在 css 中定义图像的 url 地址。
Try to define the url-address for the image in css.