2013-09-07 2 views
0

jQuery 템플릿을 사용하여 레코드를 표시하고 있습니다. 코드 colorLabel 값이 빨간색 내가 값이 빨간색을 좋아 작성하려면템플릿 필드에 CSS 적용하기

<script id="SalesTemplate" type="text/x-jquery-tmpl"> 
<form id="enterForm" action =""> 
     <tbody> 
      {{#each items}} 
      <tr class="row{{* { res += ($Number % 2); } }}"> 
       <!--td>{{=rId}}</td--> 
       <td>{{=company}}</td> 
       <td>{{=colorLabel}}</td> 
       <td>{{=dueDate}}</td> 
      </tr> 
      {{/each}}  
     </tbody>   
    </table>   
</form> 

는 내가하고 싶은 것은이며 녹색 인 경우 녹색 글꼴로 기록 될 수 있습니다. 어떤 아이디어를 어떻게 얻을 수 있습니까? 감사합니다

답변

0

색상 16 진수 또는 rgb 값이 있습니까? 그럼 당신은 할 수 :

<td style="color:{{=colorValue}}">{{=colorLabel}}</td> 

그렇지 않다면, 당신은 당신의 colorLabels가 css color names 일치하는 경우 시도하고이 할 수있는 : 또는

<td style="color:{{=colorLabel}}">{{=colorLabel}}</td> 

을, 당신은 클래스와 colorLabel을 설정하고의 색상을 설정할 수 있습니다 CSS :

<td class="{{=colorLabel}}">{{=colorLabel}}</td> 

CSS는

td.red{ 
    color:#f00; 
} 
td.blue{ 
    color:#00f; 
} 
... 
+0

{{= colorLabel}} –

0

이것은 모든 셀을 거치며 텍스트를 확인합니다. 텍스트 값이 'red'이면 글꼴 색이 빨간색으로 바뀝니다. 텍스트 값이 '녹색'이면 글꼴 색이 녹색으로 바뀝니다.

$('table td').each(function(){ 
    if ($(this).html() == 'red') { 
     $(this).css("color", "red"); 
    } else if ($(this).html() == 'green'){ 
     $(this).css("color", "green"); 
    } 
}); 
+0

이 코드는 어디에 있습니까? –