【发布时间】:2018-01-26 01:41:56
【问题描述】:
我的网站上有一个显示实时数据源的 html 表格。我正在使用 PHP、MySQL 和 AJAX 的组合来检索它。
在检索新数据时将表行添加到表中。一切都按预期进行。
我想根据 javascript 变量的内容向 <td> 添加一个字形图标。
我的html表格如下;
<table id="transactionTable">
<thead>
<tr>
<th>ID</th>
<th>Date / Time</th>
<th>Card No</th>
<th>Direction</th>
</tr>
</thead>
</table>
向表中添加行的jquery;
$("#transactionTable").prepend('<tr><td>'+data.SerialNo+'</td><td>'+dateFormatted+'</td><td>'+data.CardNo+'</td><td id="direction">'+data.Direction+'</td></tr>');
我想做的是,
// data.Direction is coming from the server
if(data.Direction == 'I') {
// add <span class="glyphicon glyphicon-import"></span>
}
if(data.Direction == 'O') {
// <span class="glyphicon glyphicon-export"></span>
}
所以表格行应该是这样的;
// if(data.Direction == 'I')
<tr>
<td>1</td>
<td>News</td>
<td>News Cate</td>
<td><span class="glyphicon glyphicon-import"></span> In</td>
</tr>
或者;
// if(data.Direction == 'O')
<tr>
<td>1</td>
<td>News</td>
<td>News Cate</td>
<td><span class="glyphicon glyphicon-export"></span> In</td>
</tr>
感谢任何建议。
【问题讨论】:
标签: javascript jquery html glyphicons