How do I change the background color with JavaScript?

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

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

19条回答
  •  花落未央
    2020-11-22 15:01

    AJAX is getting data from the server using Javascript and XML in an asynchronous fashion. Unless you want to download the colour code from the server, that's not what you're really aiming for!

    But otherwise you can set the CSS background with Javascript. If you're using a framework like jQuery, it'll be something like this:

    $('body').css('background', '#ccc');
    

    Otherwise, this should work:

    document.body.style.background = "#ccc";
    

提交回复
热议问题