0
我有標記的塊:如何捕獲選中的單選按鈕的標籤jQuery中
<fieldset class="form__list form__inlineButtons" enabled="enabled">
<label for="paymentMethod_839838" class="form__optional">
<input type="radio" value="1" name="paymentMethod" id="paymentMethod_839838" class="form__list jq__pmt1" style="display: inline-block;"> Cash
</label>
<label for="paymentMethod_570709" class="form__optional">
<input type="radio" value="2" name="paymentMethod" id="paymentMethod_570709" class="form__list jq__pmt2" style="display: inline-block;"> Check
</label>
<label for="paymentMethod_692392" class="form__optional">
<input type="radio" value="3" name="paymentMethod" id="paymentMethod_692392" class="form__list jq__pmt3" style="display: inline-block;"> Credit Card
</label>
<label for="paymentMethod_567739" class="form__optional">
<input type="radio" value="4" name="paymentMethod" id="paymentMethod_567739" class="form__list jq__pmt4" style="display: inline-block;"> Invoice
</label>
<label for="paymentMethod_227750" class="form__optional">
<input type="radio" value="5" name="paymentMethod" id="paymentMethod_227750" class="form__list jq__pmt5" style="display: inline-block;"> Payment Pending
</label>
</fieldset>
我有這個jQuery:
$('[name="paymentMethod"]').change(function() {
alert($('[name="paymentMethod"] :radio:checked + label').text());
}); // end .change()
我似乎無法捕捉到的標籤選中單選按鈕的
旁註:標籤'for'屬性是可選的,當輸入是標籤的子項 – Satpal
好的,謝謝@Satpal。標記是由我使用的開源工具生成的,因此我無法控制其創建。我只是試圖用它來添加我自己的功能層。 –