所以我想做的似乎应该很简单,但由于某些原因,它不起作用,所以可能我遗漏了一些东西。
这是JS代码
var elementTitles = new Array (
"titleOne",
"titleTwo",
"titleThree"
);
var elementCurrentTitle = document.getElementById("element-title").innerHTML;
var elementOneColor = document.getElementById("element-1-id").style.color;
var elementTwoColor = document.getElementById("element-2-id").style.color;
var elementThreeColor = document.getElementById("element-3-id").style.color;
function rotateTitleColors(){
if (elementCurrentTitle == elementTitles[0]){
elementOneColor = "black";
elementTwoColor = "grey";
elementThreeColor = "grey";
};
else if (elementCurrentTitle == elementTitles[1]){
elementOneColor = "grey";
elementTwoColor = "black";
elementThreeColor = "grey";
};
else if (elementCurrentTitle == elementTitles[2]){
elementOneColor = "grey";
elementTwoColor = "grey";
elementThreeColor = "black";
};
};
出于某种原因,它不起作用,我试着做一些非常简单的测试。
var elementOneColor = document.getElementById("element-1-id").style.color;
function logElementColor(){
console.log(elementOneColor);
};
控制台里什么也没显示。我应该如何获得css“color”属性的实际值,以便将其传递到变量中?