0

尝试找到选中的单选按钮“否”旁边的文本框的值,但失败了。

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

2 回答 2

0

try the following code: $("form input:radio[value=False]:checked").closest("input[type=text]").first().val();

于 2013-10-25T19:16:59.547 回答
0

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

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

于 2013-10-25T19:27:08.983 回答