Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 动态内容url_Jquery_Css_Less - Fatal编程技术网

Jquery 动态内容url

Jquery 动态内容url,jquery,css,less,Jquery,Css,Less,我想循环class.metric类型中的SPAN字符串值,以便该字符串(例如:“Home Icon”)可以用作@iconurl的定义,作为参数传递给最后一个声明。实际上,通过连接匹配的字符串来更新所有这些跨内容url。有什么想法吗 <span class="metric-type">Home-Icon</span> @iconurl:""; .iconStyle(@iconurl){ content:url("/location/@{iconurl}.svg"

我想循环class.metric类型中的SPAN字符串值,以便该字符串(例如:“Home Icon”)可以用作@iconurl的定义,作为参数传递给最后一个声明。实际上,通过连接匹配的字符串来更新所有这些跨内容url。有什么想法吗

<span class="metric-type">Home-Icon</span>

@iconurl:"";

.iconStyle(@iconurl){
    content:url("/location/@{iconurl}.svg");
}
.metric-type{
   .iconStyle(@iconurl);
}
已解决(改为通过jQuery):我能够通过使用
content:attr(data name)
实现一些动态函数,但它非常有限,只能获得字符串结果,因为我无法将其与其他字符串变量连接以生成图像

虽然我在这里编辑可视内容,但该语言不支持它,因此我在这里使用了全jQuery解决方案:

$('.metric-type').each(function () {
    $(this).each(function () {
            var metricName= $(this).html();
$(this).html("<img src='/filelocation"+metricName+".svg'>"+metricName);
        });
});
$('.metric-type').each(function () {
    $(this).each(function () {
            var metricName= $(this).html();
$(this).html("<img src='/filelocation"+metricName+".svg'>"+metricName);
        });
});
$('.metric type')。每个(函数(){
$(此)。每个(函数(){
var metricName=$(this.html();
$(this.html(“+metricName”);
});
});

是否希望将HTML中的值转换为LESS/CSS?这并不是HTML/CSS真正的工作原理,不清楚你想做什么。由于变量
@iconurl
是在您尝试为mixin参数使用默认值之前定义的。您可以通过简单地分配deault值来实现这一点,比如
.iconStyle(@url:@iconurl){content:url(“/location/@{url}.svg”);}
。你可以看一看,;我编辑了我的原始问题,以使其更有意义。