【问题标题】:Change background image with a button w/ jQuery使用带有 jQ​​uery 的按钮更改背景图像
【发布时间】:2016-09-08 11:54:12
【问题描述】:

我想在单击按钮时更改 div“content1”上的背景图像。

$(document).ready(function(){
  $("button").click(function(){
    $("content1").css("background-image", "url(../images/light.png)");
  });
});

.content1 {
  background-image: url('../images/dark.png');
}

我的 CSS 是外部的。

谢谢。

【问题讨论】:

  • $(".content1"),你错过了.

标签: jquery html css button background


【解决方案1】:

您的内容是一门课程。所以你需要使用正确选择的jquery。

 $(".content1").css("background-image", "url(../images/light.png)"); 

【讨论】:

  • 谢谢,我怎样才能把它变成一个切换按钮?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-08-12
  • 1970-01-01
  • 2013-09-01
  • 2013-09-07
  • 2016-07-12
  • 2011-04-15
  • 1970-01-01
相关资源
最近更新 更多