使用js设置CSS变量时转义的网址

问题描述 投票:0回答:1

im试图用js设置css自定义属性。属性的名称应为“ --path”,值应为“ url(test.png)”。

我的代码如下:

window.document.body.style.setProperty("--path", "url(test.png)");

我的问题是--path的值现在是"url(test\.png)"。我如何防止这个点转义?

javascript html css
1个回答
0
投票

在路径中添加引号:

window.document.body.style.setProperty("--path", "url('test.png')");
© www.soinside.com 2019 - 2024. All rights reserved.