2012-02-08 113 views
-1

我有一塊的jQuery這是工作的罰款在Firefox和IE,但在Chrome和Safari。顏色的JQuery無法在Chrome/Safari瀏覽器工作

if (intCurrPortionId == intOldPortionId) { 
    $('#' + portionCell + '').css("backgroundColor", "green"); 
} else { 
    $('#' + portionCell + '').css("backgroundColor", "red"); 
} 

,這是不工作不工作.. 打電話是這個jQuery的複選框onchange事件

編輯: 它不執行在Chrome和Safari的功能..我添加的警報中的代碼,並發現沒有警報是彈出...現在如何解決它

+0

爲什麼你的選擇器中有「+」符號? – 2012-02-08 13:50:35

+0

你可以驗證是否正在設置任何樣式? – 2012-02-08 13:51:23

+0

@BarryChapman m尾隨''因爲我會在ID中添加更多的變量一旦我得到這個工作.. – 1Mayur 2012-02-09 06:23:28

回答

4
$('#' + portionCell).css("background-color", "green"); 
+0

沒有工作,我想我必須去與addclass和removeclass事件nw – 1Mayur 2012-02-09 06:17:25

+0

@Sirwani做一個'alert(partCell)'看看'partCell'不是空的或無效 – mgraph 2012-02-09 08:50:50

+0

你的建議很有幫助..發現該函數沒有在chrome中執行..沒有警報彈出..需要排序y是它顯示奇怪的行爲.. – 1Mayur 2012-02-21 07:06:41

0

嘗試使用background-color

if (intCurrPortionId == intOldPortionId) { 
    $('#' + portionCell + '').css("background-color", "green"); 
} else { 
    $('#' + portionCell + '').css("background-color", "red"); 
} 

僅供參考,使用JavaScript風格的參數名稱(如backgroundColor)我在這裏工作正常,在Safari 5.1.2和Chrome 16:

Test fiddle