通过单击链接(兄弟姐妹?)从无线电输入中获取id

时间:2012-08-29 10:13:21

标签: javascript jquery html

所以我有一个地址列表,每个地址都有编辑链接,我想获取列表项中输入的ID

<li class="last">
    <div class="checkout-select-address"><input type="radio" name="checkout_selected_address" id="checkout_selected_address_3" value="" /></div>
    <div class="checkout-select-address-details">
    <p><label for="checkout_selected_address_3">(Mothers)</label> <a href="#" title="Edit Address" class="edit-link right">Edit Address</a></p>
    <input type="hidden" id="checkout_selected_address_3_name" value="" />
    <input type="hidden" id="checkout_selected_address_3_title" value="" />
    <input type="hidden" id="checkout_selected_address_3_first_name" value="" />
    <input type="hidden" id="checkout_selected_address_3_last_name" value="" />
    <input type="hidden" id="checkout_selected_address_3_address_line_1" value="" />
    <input type="hidden" id="checkout_selected_address_3_address_line_2" value="" />
    <input type="hidden" id="checkout_selected_address_3_address_line_3" value="" />
    <input type="hidden" id="checkout_selected_address_3_town_city" value="" />
    <input type="hidden" id="checkout_selected_address_3_county" value="" />
    <input type="hidden" id="checkout_selected_address_3_postcode" value="" />
    <input type="hidden" id="checkout_selected_address_3_country" value="" />
</div>
<div class="clear"></div>

所以点击带有“edit-link”类的链接,它将获得li中无线电输入的ID

提前致谢

1 个答案:

答案 0 :(得分:0)

试试这个:

$(".edit-link").click(function(){
   alert($(this).closest("li").find("input[type=radio]").attr("id"));
});

演示:http://jsfiddle.net/ZABBS/