js Cannot set property 'color' of undefined

js 动态加载td   :$('#thead').after(""+nCode+"");


获取tdstyle:

var templetList = $('#code'+nCode);
//  $('#code'+nCode).style.color="green";
    if(templetList.style.color=="red"){
      templetList.style.color="green";
  }else{
    templetList.style.color="red";
  }

报错:Cannot read property 'color' of undefined


解决:jQuery对象没有style属性,样式通过css设置

    var templetList = $('#code'+nCode);
    var color = templetList.css("color");
    if('rgb(0, 0, 0)'==color){
        templetList.css("color","RoyalBlue");
    }else{

        templetList.css("color","black");  

   }

你可能感兴趣的:(js,css)