[Ctrl+A 全選 注:如需引入外部Js需刷新才能執行]
下面是對一些數字進行格式化
我們想改變這麼一段代碼中間td之間的文本
<table>
<tr id='generated_rows'>
<td class='row_class' id='row_id_1'>1</td>
<td class='row_class' id='row_id_2'>2</td>
<td class='row_class' id='row_id_3'>3</td>
<td class='row_class' id='row_id_4'>4</td>
<td class='row_class' id='row_id_5'>5</td>
</tr>
</table>
實現顯示為:
<table>
<tr id='generated_rows'>
<td class='row_class' id='row_id_1'>1.00</td>
<td class='row_class' id='row_id_2'>2.00</td>
<td class='row_class' id='row_id_3'>3.00</td>
<td class='row_class' id='row_id_4'>4.00</td>
<td class='row_class' id='row_id_5'>5.00</td>
</tr>
</table>
實現的函數為:
$('#generated_rows td.row_class').each(function() {
var x = Number($(this).text()).toFixed(2);
$(this).text(x);
});
演示代碼
[Ctrl+A 全選 注:如需引入外部Js需刷新才能執行]