How do I change the background color with JavaScript?

后端 未结 19 2288
春和景丽
春和景丽 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:58

    You don't need AJAX for this, just some plain java script setting the background-color property of the body element, like this:

    document.body.style.backgroundColor = "#AA0000";
    

    If you want to do it as if it was initiated by the server, you would have to poll the server and then change the color accordingly.

提交回复
热议问题