2014-09-01 93 views
0

在下面的代碼中,該腳本正在打開和關閉div。所述.style 代碼,控制和關閉被切換 在div的父元素的背景顏色。該代碼適用於Opera,但不適用於Chrome,我一直無法搜索(搜索)解決方案。Chrome not handling .style =「background-color:#333223;」

我當然可以繼續前進,寫其他代碼,實現我需要什麼,但現在我有好奇心 起來。

function CheckOutOpn(){ 
    var Inny = document.getElementById("RightPaneASxOrderForm"); 
    MVxCheckOutForm(); 
    CDxButtonOpnChkOut(); 
    MVxCLOSExBttnChkout(); 
    Inny.style = "background-color:#332223;"; 
} 

function CLOSExCheckOut(){ 
    var Inny = document.getElementById("RightPaneASxOrderForm"); 
    MVxButtonOpnChkOut(); 
    CDxCLOSExBttnChkout(); 
    CDxOrderFormItself(); 
    Inny.style = "background-color:#33B32E;"; 
} 
+0

任何控制檯錯誤? – Justinas 2014-09-01 10:58:41

+1

很難相信這個代碼將在任何瀏覽器中工作... – Teemu 2014-09-01 11:01:17

+0

@Teemu LOL好,也許當分曉和V8殺死歌劇院將不再在任何地方工作。 – MountainMan 2014-09-01 11:08:15

回答

2

,我認爲你應該使用:

Inny.style.backgroundColor = "#332223"; 

https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement.style

...除了在Opera,樣式不能通過向 指定的字符串設定(只讀)樣式屬性,如在elt.style =「color:blue;」中所示。這是 ,因爲style屬性返回一個CSSStyleDeclaration對象。

+0

對,所以歌劇不是那麼古怪,嗯。在任何案例中,明白了。應該使用CamelCase。謝謝。 – MountainMan 2014-09-01 11:04:35

1

如果你想設置一個元素的樣式文本上,您需要爲使用

Inny.style.cssText="background-color:#33B32E" 

Inny.setAttribute("style","background-color:#33B32E") 

,或者你可以直接設置屬性:

Inny.style.backgroundColor = "#33B32E"; 
0

我認爲這會爲你工作的罰款。只有當你將css屬性添加到元素時,你所做的錯誤是。

function CheckOutOpn(){ 
    var Inny = document.getElementById("RightPaneASxOrderForm"); 
    MVxCheckOutForm(); 
    CDxButtonOpnChkOut(); 
    MVxCLOSExBttnChkout(); 
    Inny.style.backgroundColor = "#332223"; 
}