爲什麼div的背景顏色不更新?bgColor不通過JavaScript更新
Tagger.prototype.mouseDown = function(event) {
this.element.style.posLeft = event.clientX;
this.element.style.width = 200 + "px";
this.element.style.height = 200 + "px";
this.element.style.position = "absolute";
this.element.style.zIndex = 10;
this.element.style.bgColor = "yellow";
console.log(this.element);
console.log(this.element.style.bgColor);
}
控制檯輸出爲:
<div id="tagbox4" class="tagbox" style="width: 200px; height: 200px; position: absolute; z-index: 10;">
yellow
我可以在瀏覽器中檢查元素選擇div,但它沒有背景色,即使在控制檯說,這是「黃色」。
...再次,我會建議使用庫進行這種操作。在http://api.jquery.com/css/#css2上使用jQuery'.css()'是一件輕而易舉的事 - 最後一個例子 –
CSS中沒有'bgColor' ... –