js Cannot set property 'color' of undefined

来源:互联网 发布:软件视频会议排名 编辑:程序博客网 时间:2024/05/22 14:59

js 动态加载td   :$('#thead').after("<tr><td id='code"+nCode+"' style='cursor:pointer;color:black;' onclick='crawlTempleTest("+nCode+","+tplGrade+");'>"+nCode+"</td></tr>");


获取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");  

   }

阅读全文
0 0
原创粉丝点击