我有下面的代码放置多次在页面上一些在一张桌子和一些工具提示:jQuery的 - 遍历标签/输入对,并添加唯一的ID
<p class="radioBtn">
<label for="business"></label>
<input id="business" type="radio" name="radioBtn" value="" />
</p>
<p class="radioBtn">
<label for="private"></label>
<input id="private" type="radio" name="radioBtn" value="" />
</p>
我想知道怎么回事,使用jQuery,我可以遍历整个页面,并在标签'for'属性的末尾添加一个唯一的ID号码,并输入'id',这样我就可以得到如下每个配对唯一的内容:
<p class="radioBtn">
<label for="business0"></label>
<input id="business0" type="radio" name="radioBtn" value="" />
</p>
<p class="radioBtn">
<label for="private0"></label>
<input id="private0" type="radio" name="radioBtn" value="" />
</p>
非常感谢提前。
'input'和'label'元素之间的比例是否为1:1? – 2010-12-12 15:38:38
@大卫是的。最后,这些配对将从数据库中添加,因此在任何给定的时间内最多可以配对100个配对。 'for'和'id'必须匹配,因为我使用JS来改变其外观。 – mtwallet 2010-12-12 15:44:23