我有一个随机更改页面背景颜色的功能以及具有相同颜色的文本。问题:当背景为白色时,文本也是白色。为了解决这个问题,我想创建一个函数,当背景为白色时将文本更改为黑色。
function changetitlecolor() {
if (document.body.style.backgroundColor= "#ffffff"){
document.getElementById("title").style.color="#000000";
document.getElementById("message").style.color="#000000";
}
}
上面的代码确实改变了文本颜色,但它也将页面背景更改为白色,我不希望这种情况发生。