使用jquery我想为一系列div添加一个id,但当然id需要总是不同的,所以我想有一个渐进的数字,比如id =“1”,id =“2”,id =“3”等。
这是我的标记:
内容
<div class="box">
<p>
content
</p>
</div>
<div class="box">
<p>
content
</p>
</div>
<div class="box">
<p>
content
</p>
</div>
我尝试了一个.each()循环,但我不知道要传递什么作为集合(可能是$('。box')。lenght()?但返回的数字不是集合)以及如何实现回调功能。 有什么帮助吗?
提前致谢:)
莫罗