繁体   English   中英

如何在jQuery中捕获选中的单选按钮的标签

[英]How to capture the label of a checked radio button in 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()

我似乎无法捕获选中的单选按钮的标签

你会这样做-

$('[name="paymentMethod"]').change(function() {
    var label = $(this).closest('label').text();
    alert(label);
}); // end .change()

http://jsfiddle.net/MBz4k/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM