簡體   English   中英

HandlebarsJS :根據文本值更改文本顏色?

[英]HandlebarsJS : Change the text color depending what text value is?

在我的handlebars電子郵件HTML模板中,我有下表:

<div class="table">
        <table id="carTable">
            <tbody>
            <tr>
                <th>Car Number</th>
                <th>owner</th>
            </tr>
            <!-- {{#each car}} -->
            <tr>
                <td>{{carNumber}}</td>
                <td>{{owner}}</td>
            </tr>
            <!--{{/each}} -->
            </tbody>
        </table>
    </div>

是否有可能如果{{owner}}的值是例如“foo”那么文本將是紅色的,如果值是“bar”那么它會是藍色等?

使用車把,您需要編寫如下內容:

<tr {{#if owner === "foo"}} class="red-text" {{/if}}>{{owner}}</tr>

看看這個例子

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM