jquery找到最接近的文本框

时间:2013-10-25 19:10:07

标签: jquery jquery-selectors

尝试找到radiobutton“no”旁边的文本框的值,但是失败了。

$("form input:radio[value=False]:checked").closest(".txt").first().val();

html代码如下所示:

    <span id="RadioButtonList1" style="display:inline-block;width:100px;">
    <input id="RadioButtonList1_0" type="radio" name="RadioButtonList1" value="true" />
    <label for="RadioButtonList1_0">Yes</label>
    <input id="RadioButtonList1_1" type="radio" name="RadioButtonList1" **value="False" checked="checked"** />
    <label for="RadioButtonList1_1">No</label>
</span>
<span id="RequiredFieldValidator1" style="visibility:hidden;">*</span>
<input name="TextBox1" type="text" value="pp" id="TextBox1" Class="txt" />
<br />
<span id="RadioButtonList2" style="display:inline-block;width:100px;">
    <input id="RadioButtonList2_0" type="radio" name="RadioButtonList2" value="true" checked="checked" />
    <label for="RadioButtonList2_0">Yes</label>
    <input id="RadioButtonList2_1" type="radio" name="RadioButtonList2" value="False" />
    <label for="RadioButtonList2_1">No</label>
</span>
<span id="RequiredFieldValidator2" style="visibility:hidden;">*</span>
<input name="TextBox2" type="text" id="TextBox2" Class="txt" />
<br />
<span id="RadioButtonList3" style="display:inline-block;width:100px;">
    <input id="RadioButtonList3_0" type="radio" name="RadioButtonList3" value="true" checked="checked" />
    <label for="RadioButtonList3_0">Yes</label>
    <input id="RadioButtonList3_1" type="radio" name="RadioButtonList3" value="False" />
    <label for="RadioButtonList3_1">No</label>
</span>
<span id="RequiredFieldValidator3" style="visibility:hidden;">*</span>
<input name="TextBox3" type="text" id="TextBox3" Class="txt" /><br />

2 个答案:

答案 0 :(得分:0)

尝试以下代码:     $(“表格输入:radio [value = False]:选中”)。最近(“input [type = text]”)。first()。val();

答案 1 :(得分:0)

以下内容可能有效:$( "form input:radio[value=False]:checked" ).parent().next( ".txt" ).val();

基本上检测所需的复选框(就像你已经做过的那样),跳转到父元素并选择类.txt的下一个元素。