嘗試查找單選按鈕旁邊的「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 />
你試過.nextAll()而不是.closest()嗎?這是我會用來找到符合條件的dom中的下一個元素。 –
@MikeLong'.closest'將匹配收音機最近的父元素。使用'.parent()。nextAll('。txt')。first()' – hitautodestruct
是的,我做了但失敗了。 –