日期:2014-05-16  浏览次数:20391 次

js 改td背景色,ie中如果不用兼容性视图或firefox中无效
代码如下,请各位帮忙看看如何修改才能在firefox下有效
function color()
  {
  for(var j=1;j<=MonthDays;j++){
  for(var i=1;i<=10;i++){
  var line,row; 
  line="hh_"+j+"_11";
  row="hh_"+j+"_"+i+"";

  if(document.getElementById(line).value==0){
  document.getElementById(row).style.backgroundColor="#cc99cc";

  }
  }
  }
  }
背景色

------解决方案--------------------
看看有没有定义属性id
hh_1_1
hh_1_2
.
.
.
hh_2_1
.
.
.
.
------解决方案--------------------
  line="hh_"+j+"_11";
  row="hh_"+j+"_"+i;
  
  if(document.getElementById(line).value==0){
  document.getElementById(row).style.backgroundColor="#cc99cc";

你的 id 都是组装的,需先验证存在
if(document.getElementById(line) && document.getElementById(row)) {
  if(document.getElementById(line).value==0){
  document.getElementById(row).style.backgroundColor="#cc99cc";