im试图用js设置css自定义属性。属性的名称应为“ --path”,值应为“ url(test.png)”。
我的代码如下:
window.document.body.style.setProperty("--path", "url(test.png)");
我的问题是--path的值现在是"url(test\.png)"
。我如何防止这个点转义?
在路径中添加引号:
window.document.body.style.setProperty("--path", "url('test.png')");