Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我能够使用 jQuery 创建一个随机数并将其放入<td>. 但是我可以让每个<td>人都有自己的随机数吗?
<td>
我建议:
$('td').text(function(){ return Math.random(); // or however you want to generate your random number });
JS 小提琴演示。
上面遍历每个td元素并独立于其他元素设置其文本td,不像:
td
$('td').text(Math.random());
它为所有元素设置相同的随机数。td
参考:
text()