How do I change the background color with JavaScript?

后端 未结 19 2235
春和景丽
春和景丽 2020-11-22 13:59

Anyone know a simple method to swap the background color of a webpage using JavaScript?

19条回答
  •  有刺的猬
    2020-11-22 14:41

    Alternatively, if you wish to specify the background color value in rgb notation then try

    document.getElementById("yourid").style.backgroundColor = 'rgb(' + a + ',' + b + ',' + c + ')';
    

    where a,b,c are the color values

    Example:

    document.getElementById("yourid").style.backgroundColor = 'rgb(224,224,224)';
    

提交回复
热议问题