我目前正在尝试将 JS 变量的属性从 url("../images/video.png")(它在 CSS 中的声明方式)更改为 url("../images/pause. png") 通过这行代码:
fullscreenPlayPauseButton.style.backgroundImage = "url("../images/pause.png")";
将鼠标悬停在图像上会显示图像,并且两个图像都在文件夹中。但是,一旦执行了这行代码,最初显示的图像(video.png)就会变成灰色。我在控制台中遇到的错误是“Uncaught SyntaxError: Unexpected token”。在该代码所在的行上。在此先感谢您的帮助!
最佳答案
您在一行中使用了两个双引号。您必须转义它们或使用单引号:
fullscreenPlayPauseButton.style.backgroundImage = "url('../images/pause.png')";
或
fullscreenPlayPauseButton.style.backgroundImage = "url(\"../images/pause.png\")";
两者都应该有效。
关于javascript - 如何在 JS 中更改背景图片属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38213138/