如何使用javascript将颜色设置为CSS [英] How to set color to span in CSS using javascript

查看:49
本文介绍了如何使用javascript将颜色设置为CSS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我已根据表达式在我的仪表板中添加了表情符号。



基于在它必须显示笑脸颜色为绿色和红色的百分比。



这里我用javascript写了一个方法



Hi,

I have added emoji's in my dashboard based on the expression.

Based on the percentage it has to show smiley with color as green and red.

Here i have written one method in javascript

function setColors(args) {
        var textClientData = DashboardViewer.GetItemData("textBoxDashboardItem1");
        var value = textClientData.GetMeasureValue(textClientData.GetMeasures()[2].Id).GetValue();
        if (value=="J")
        var result = value.toString().fontcolor("Green");
        document.getElementsByClassName('cs10E8CA05').css('color','Green');
        //x.style.color = "Green";
        //var score = $('#cs10E8CA05').text().trim();
        //var color = 'red';
        //$('#cs10E8CA05').css('color', color);
};





如果值为J则必须为绿色。

如果值为L,那么它必须是红色。



我已经检查了浏览器中的网络选项卡,它位于跨度下。



如何使用javascript调用css为跨度设置颜色。



请建议我。



我尝试过:





If the value is J then it has to be in green color.
If the value is L then it has to be in red color.

I have checked the network tab in browser and it is lying under the span.

How to set color for the span by using javascript call to css.

Please suggest me.

What I have tried:

function setColors(args) {
        var textClientData = DashboardViewer.GetItemData("textBoxDashboardItem1");
        var value = textClientData.GetMeasureValue(textClientData.GetMeasures()[2].Id).GetValue();
        if (value=="J")
        var result = value.toString().fontcolor("Green");
        document.getElementsByClassName('cs10E8CA05').css('color','Green');
        //x.style.color = "Green";
        //var score = $('#cs10E8CA05').text().trim();
        //var color = 'red';
        //$('#cs10E8CA05').css('color', color);
};





这是HTML





This is HTML

<span class="cs10E8CA05">L</span>




<span class="cs10E8CA05">J</span>

推荐答案

('#cs10E8CA05')。text()。trim();
// var color ='red';
//
('#cs10E8CA05').text().trim(); //var color = 'red'; //


('#cs10E8CA05')。css('color',color);
};
('#cs10E8CA05').css('color', color); };





如果值为J则必须为绿色。

如果值为L,那么它必须是红色。



我已经检查了浏览器中的网络选项卡,它位于跨度下。



如何使用javascript调用css为跨度设置颜色。



请建议我。



我尝试过:





If the value is J then it has to be in green color.
If the value is L then it has to be in red color.

I have checked the network tab in browser and it is lying under the span.

How to set color for the span by using javascript call to css.

Please suggest me.

What I have tried:

function setColors(args) {
        var textClientData = DashboardViewer.GetItemData("textBoxDashboardItem1");
        var value = textClientData.GetMeasureValue(textClientData.GetMeasures()[2].Id).GetValue();
        if (value=="J")
        var result = value.toString().fontcolor("Green");
        document.getElementsByClassName('cs10E8CA05').css('color','Green');
        //x.style.color = "Green";
        //var score =


('#cs10E8CA05')。text()。trim();
// var color ='red';
//
('#cs10E8CA05').text().trim(); //var color = 'red'; //


这篇关于如何使用javascript将颜色设置为CSS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆