下面是对一些数字进行格式化
我们想改变这么一段代码中间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);
});
演示代码