Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 通过单击链接从无线电输入获取id(兄弟姐妹?)_Javascript_Jquery_Html - Fatal编程技术网

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

Javascript 通过单击链接从无线电输入获取id(兄弟姐妹?),javascript,jquery,html,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="checkou

所以我有一个地址列表,每个地址都有编辑链接,我想在列表项中获取输入的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>
  • (母亲)

  • 因此,点击带有“编辑链接”类的链接,它将获得li中无线电输入的ID

    提前感谢

    试试这个:

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

    演示:

    我在这个例子中没有定义,加上将有多个地址,所以需要通过单击当前LII中的链接来指定唯一的无线电id。我刚刚使用:alert($(this.nest(“li”).find(“输入[名称=签出所选地址])).attr(“id”)@选择器表达式中的mgraph属性值必须遵循W3C CSS选择器的规则,通常这意味着除了简单标识符之外的任何内容都应该用引号括起来