【发布时间】:2011-03-20 17:01:12
【问题描述】:
我想将以下内容添加到页面中:
当一个 div 被点击时,我想:
- 改变被点击的 div 的背景颜色几秒钟
- 几秒钟后恢复为原始背景颜色
我想通过仅使用 jQuery 可用函数来做到这一点 - 即不使用插件或其他任何东西。我对 jQuery 比较陌生,但我认为可能的解决方案涉及使用更改所选 div 的类和使用计时器。
我不知道如何将它们放在一起。谁能提供几行说明如何做到这一点?
这是我目前所拥有的:
$(function(){
$('div.highlightable').click(function(){
//change background color via CSS class
$(this).addClass('highlighted);
//set a timer to remove the highlighted class after N seconds .... how?
});
});
【问题讨论】:
标签: jquery