我有下面的代碼放置多次在頁面上一些在一張桌子和一些工具提示: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