2014-07-11 2 views
1

jquery를 사용하여 표 행의 색상을 변경하려고합니다. 나는 일종의 일종이지만 일종의 일을하지 않았습니다. 그때 내 모든 행이 강조 얻을 if 문 외부로 가지고가는 경우에 여기에테이블 셀의 Jquery 색상이 변경되지 않습니다.

내 기능은 ...

$("#tabHistoryBackups tr").each(function() { 
    var startTimestampStr = $(this).find("td").eq(3).html(); 
    if (!isEmpty(startTimestampStr)){ 

     startTimestampStr = startTimestampStr.replace(/\-/g, " "); 
     startTimestampStr = startTimestampStr.replace(/\./g, " "); 
     startTimestampStr = startTimestampStr.split(" "); 
     var startDateTimestamp = 
      new Date (startTimestampStr[0], startTimestampStr[1]-1, startTimestampStr[2]);    

     var today = $.now(); 
     var todaysDt = new Date(today); 
     todaysDt.setHours(0,0,0,0)  

     if (startDateTimestamp == todaysDt) { 
      $(this).find("td").css('background-color','yellow'); 
     }   
    } 

}); 

내가 가진 문제는 ...

$(this).find("td").css('background-color','yellow'); 

함께. 그러나 위에 표시된 것처럼 if 문 내부에있을 때 더 이상 강조 표시가 작동하지 않습니다.

누군가가 나에게 도움이 될 수 있습니까?

감사

+1

@Saksham? startDateTimestampStr은 날짜 객체가 아닙니다 –

+0

HTML을 알려주시겠습니까? – naota

+0

Startdatetepstampstr이 (가) 날짜 개체가 아닙니다. 나는 그것을 통제 할 수 없다. – Richie

답변

0

체크 그냥 문자열 비교와 간단 할 수 있습니다 이유

startTimestampStr = startTimestampStr.replace(/\./g, "-"); 

var now = $.now(); 
var nowStr = now.getMonth() + "-" + now.getDate() + "-" + now.getFullYear(); 

if (nowStr == startTimestampStr) 
관련 문제