替换CSS样式中的一个属性



我有风格的机身

background: url('hereSomeImg')

当我做时

document.body.style.background = 'url(../img/apple_true.jpg)'

其他样式不起作用。这只是背景。我怎样才能救他们?

您可以编辑代码:

document.body.style.background = 'url("../img/apple_true.jpg")'

你应该把url用双引号括起来。

我不确定这是否正是你想要的,从我在你的评论中看到的,你可以尝试将document.body.style["background-size"]设置为你想要的任何值。

最新更新