繁体   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