2013-10-25 60 views
0

尝试查找单选按钮旁边的“no”选中的文本框的值,但失败。jquery查找最接近的文本框

$("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 /> 
+0

你试过.nextAll()而不是.closest()吗?这是我会用来找到符合条件的dom中的下一个元素。 –

+0

@MikeLong'.closest'将匹配收音机最近的父元素。使用'.parent()。nextAll('。txt')。first()' – hitautodestruct

+0

是的,我做了但失败了。 –

回答

0

尝试以下代码: $( “形式的输入:无线​​电[值= FALSE]:检查”)。最近的(“输入[类型=文本]“)第一()VAL()。;

+0

谢谢,但得到了“未定义” –

+0

试试这个$(“form input:radio [value = False]:checked”)。 – LHH

+0

为什么我尝试了所有这些方法,都是**“未定义”** –

0

下可以正常工作:$("form input:radio[value=False]:checked").parent().next(".txt").val();

基本上检测所需的复选框(因为你已经做了),跳转到父元素,并与.txt类选择下一个元素。