html - css 样式表 :hover does not work when background image set from js.

标签 html css

我有一个 div,我向其中添加了表格列表,以创建菜单效果,我使用 CSS 样式为每个表格设置背景,如下所示:

table
{
  background: url('normal.png') no-repeat right top;
  cursor: pointer;
  margin: 0px;
}

我在 Hover 事件中改变表格的背景图片如下:

table:hover
{
  background: url('hover.png') no-repeat right top;
}

我想做的是,当用户点击其中一个表格时,我想显示一些不同的背景图像,并且它应该一直保留在那里,直到用户从列表中选择另一个表格。

如何在 CSS 中存档。

谢谢。

最佳答案

我认为仅使用 CSS 无法实现这一目标。

我会尝试使用 jQuery 向表中添加和删除类。

关于html - css 样式表 :hover does not work when background image set from js.,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5937116/

相关文章:

javascript - HTML5 + JS : Tracking user interaction

css - 时尚的 CSS 有没有效果?时尚的 CSS 顺序?

javascript - 带输出的 HTML 范围 slider

javascript - Jqmath 产生奇怪的行为,不正确的渲染

html - 为什么我的带有五个 20% 宽度 <li> 的 <ul> 导航栏在 100% 宽度的父 div 中开始一个新行?

html - Dart中的Dartium和Web Audio API导致声音失真

html - 尝试使用绝对位置使 div 出现在悬停时。需要帮助居中

css - 如何在 Rails 模型中使用 Bootstrap 表单选择 css?

php - 如何在 Wordpress 中添加对评论的回复

html - 在此上下文中,元素样式不允许作为元素主体的子元素。 (抑制来自该子树的更多错误。)