我有一個div,我想根據div中的int值更改顏色,但由於某些原因,它不會根據我寫的if else語句更改顏色。而不會出現顏色。這是爲什麼?Javascript if if問題
<div id="test">66</div>
JAVASCRIPT
var testDiv = document.getElementById("test");
if (testDiv<50) {
testDiv.style.backgroundColor = '#900000';
} else if (testDiv > 49 && testDiv < 75) {
testDiv.style.backgroundColor = '#FF9933';
} else if (testDiv > 74) {
testDiv.style.backgroundColor = '#00CC00';
}
爲什麼'testDiv'是數字,或以任何方式相當於一個數字,它顯然是一個元素 – adeneo 2015-02-05 22:51:17
你可能想'parseInt函數(testDiv.innerHTML,10)' – adeneo 2015-02-05 22:52:44