我遇到了问题,但不知道解决方案。 这是我的 HTML
<div id="thumb">
</div>
CSS:
#thumb {
width: 100%;
position: relative;
height: 557px;
background-image: linear-gradient(
rgba(252, 191, 73, 0.3),
rgba(252, 191, 73, 0.3)
),
url("../img/thumb.jpg");
background-position: center;
background-size: cover;
background-repeat: no-repeat;
background-attachment: fixed;
text-align: center;
color: #000;
}
JS:
var sliderGet = document.getElementById("thumb").style.backgroundImage;
sliderGet = 'url("../img/thumb2.jpg")';
无法使用js更改为thumb2.jpg...
最佳答案
你可以试试这个
document.getElementById("thumb").style.backgroundImage = 'url("../img/thumb2.jpg")'
关于javascript - 使用 JS 从 CSS 更改背景图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60067466/