【发布时间】:2015-09-08 23:57:00
【问题描述】:
以下是供参考的代码。变量“imgpath”的值在加载时更改。我需要为“icon1”类的背景图像分配这个新值。 我知道这可以使用 JavaScript/jQuery 来完成,但我需要一些方法来更新 CSS 本身中的这个值。 是否可以使用 Sass/Less 或任何其他方式?
<html>
<head>
<style>
.icon1 {
background: transparent url("imagepath1/icon1.png") no-repeat center center;
</style>
</head>
<body>
<a class="icon1"></a>
<script>
var imgpath = "imagepath1";
if (setnewpath)
imgpath = "imagepath2";
</script>
</body>
</html>
感谢您的帮助!
【问题讨论】:
-
感谢您的回复,但我知道如何使用 javascript/jquery。但我需要知道是否可以使用 sass/less?
-
无法用css或sass访问javascript变量,可以考虑运行nodeJS。
标签: javascript jquery css sass less