为标签提供bg颜色 [英] To provide bg color to tag

查看:95
本文介绍了为标签提供bg颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





i想在javascript中编写一个函数,它会比较我下拉的值和不同的值。我需要为bg颜色着色那个单元格。



我厌倦了这样的事情

Hi,

i want to write a function in javascript which will compare the value from my drop down and for different values..i need to color the bg color of that cell.

I tired something like this

function colorValue()
{
    var activeCompletedOnHold = form.active_Completed_OnHold.value;
   
    if(activeCompletedOnHold=="Active1")
    {
        this.style.background-color=#347C17;
    }
    else if(activeCompletedOnHold=="Completed")
    {
         //this.style.background-color='#347C17';
    }
    else if(activeCompletedOnHold=="On Hold")
    {
    //this.style.background-color='#FF0000';
    }
}







请让我知道这有什么问题。




Please let me know what is wrong in this.

推荐答案

使用Javascript时,必须将连字符CSS属性转换为驼峰情况:

Hyphenated CSS attributes have to be converted into camel case when using Javascript:
function colorValue()
{
    var activeCompletedOnHold = form.active_Completed_OnHold.value;

    if(activeCompletedOnHold=="Active1")
    {
        this.style.backgroundColor='#347C17';
    }
    else if(activeCompletedOnHold=="Completed")
    {
         //this.style.backgroundColor='#347C17';
    }
    else if(activeCompletedOnHold=="On Hold")
    {
    //this.style.backgroundColor='#FF0000';
    }
}





您还需要围绕颜色值的报价。



(假设是支持背景颜色样式的元素)



You do need quotes around the colour value too.

(This is assuming that this is an element that supports a background-color style)


this指的是窗口对象。

当你更改样式属性时你无法使用破折号( - )而不是你使用cammel案例编写属性,所以:



background-color 将是 backgroundColor



您想在更改下拉列值时更改特定元素的颜色吗? br />
该特定元素是下拉列表的父级还是另一个随机元素?



如果您想要的是更改下拉列表背景颜色,例如,你的功能可能是:



"this" refers to the window object.
and when you are changing style property you cannot use dash(-) instead you write the properties using cammel case, so:

background-color will be backgroundColor

Do you want to change the color of a specific element when your dropdown value is changed?
Is that specific element the "parent" of the dropdown or is another "random" element?

if what you want is change the dropdown background color, for example, your function could be:

function colorValue() {
       var activeCompletedOnHold = form.active_Completed_OnHold.value;

       if(activeCompletedOnHold==="Active1")
       {
           form.active_Completed_OnHold.style.backgroundColor="#347C17";
       }
       else if(activeCompletedOnHold==="Completed")
       {
           form.active_Completed_OnHold.style.backgroundColor='#0000FF';
       }
       else if(activeCompletedOnHold==="On Hold")
       {
           form.active_Completed_OnHold.style.backgroundColor='#FF0000';
       }
   }


这篇关于为标签提供bg颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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