gpt4 book ai didi

javascript - 将随机数插入到类中

转载 作者:行者123 更新时间:2023-12-01 01:59:21 24 4
gpt4 key购买 nike

如果我这样做:

$('.classname').html(Math.floor(Math.random()*10)+1);

所有“classname”都用相同的数字填充。是否可以用不同的随机数填充“classname”的每个实例?

我能想到解决这个问题的唯一可能的方法是遍历“类名”的每个实例并一一应用随机数。

最佳答案

.html()

$(".classname").html(function(idx, oldValue) {
return (Math.floor(Math.random()*10)+1);
});

fiddle

关于javascript - 将随机数插入到类中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11603618/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com