2012-02-08 114 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