对不起noob问题,但我试图将此javascript函数应用于html表中的数据。该功能来自this Stack Overflow post。将javascript函数应用于html元素
function numberWithCommas(x) {
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}
我想这个功能适用于这样的事情:
<table>
<tr>
<td>5000</td>
<td>5600</td>
</tr>
</table>
与返回的5000下一个5600的希望。我无法弄清楚这个简单的事情。我知道我需要在其中一个标签上使用标识或类,并且这需要匹配功能中的某些东西,所以我试过
<table>
<tr class="numberWithCommas">
<td>5000</td>
<td>5600</td>
</tr>
</table>
无济于事。我相信这个功能可以提供大量的upvotes。
能有一个灵魂请走过我的步骤,使这项工作?我已经搜索了一个基本的教程,并没有发现任何东西。
您可以使用jQuery吗? – NunoCarmo