我有一个转发器:
<asp:Repeater ID = "rpQuestion8" runat = "server" >
<ItemTemplate>
<tr>
<td>
<asp:DropDownList ID = "ddCounty" runat = "server" AutoPostBack="true" />
<input type = "hidden" id = "hidSurveyCustomerAreaID" runat = "server" value = '<%#showData(Container.DataItem, "SurveyCustomerAreaID")%>' />
</td>
<td>
<asp:radiobutton id = "radStillStandHuntMethod" text = "Still/Stand" runat = "server" GroupName = "Question8HuntMethod"/>
<asp:radiobutton id = "radDogHuntMethod" text = "Dog" runat = "server" GroupName = "Question8HuntMethod"/>
</td>
<td>
<asp:TextBox ID = "txtDaysHunted" runat = "server" Width = "50" text = '<%#showData(Container.DataItem, "DaysHunted")%>'/>
<asp:CompareValidator ID = "cvNumDays" runat = "server" ControlToValidate = "txtDaysHunted" Operator = "DataTypeCheck" Type = "Integer" Text = "*" ErrorMessage = "Please enter a whole number for Days Hunted." />
</td>
<td>
<asp:radiobutton id = "radYesUnprocessedFood" text = "Yes" runat = "server" GroupName = "Question8UnprocessedFood" />
<asp:radiobutton id = "radNoUnprocessedFood" text = "No" runat = "server" GroupName = "Question8UnprocessedFood" />
</td>
<td>
<asp:TextBox ID = "txtNumSeen" runat = "server" Width = "50" text = '<%#showData(Container.DataItem, "NumberSeen")%>' />
<asp:CompareValidator ID = "cvBearsSeen" runat = "server" ControlToValidate = "txtNumSeen" Operator = "DataTypeCheck" Type = "Integer" Text = "*" ErrorMessage = "Please enter a whole number for Number of Bears Seen." />
</td>
<td>
<asp:radiobutton id = "radYes" text = "Yes" runat = "server" GroupName = "Question8Harvest" />
<asp:radiobutton id = "radNo" text = "No" runat = "server" GroupName = "Question8Harvest" />
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
jQuery的:
<script src="../../../Javascript/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
function ddCountyChange(sender) {
if (sender.value === "") {
$(sender).parent().siblings().find("input").attr("disabled", "disabled");
$(sender).parent().siblings().find("input").val('');
$(sender).parent().siblings().find("input").prop('checked', false);
$(sender).parent().siblings().find("label").css("color", "#cccccc");
$(sender).parent().siblings().find("input").val('');
} else {
$(sender).parent().siblings().find("input").removeAttr('disabled');
$(sender).parent().siblings().find("label").css("color", "#000000");
}
}
</script>
我希望能够删除隐藏输入的值(id =&#34; hidSurveyCustomerAreaID&#34;)。上面的jQuery代码为转发器中的所有输入执行此操作,除了(id =&#34; hidSurveyCustomerAreaID&#34;)。
答案 0 :(得分:1)
我将此添加到JQuery代码中:
$(sender).parent().find("input").val('');
这将访问下拉列表所在的td
内的输入。
function ddCountyChange(sender) {
if (sender.value === "") {
$(sender).parent().siblings().find("input").attr("disabled", "disabled");
$(sender).parent().siblings().find("input").val('');
$(sender).parent().find("input").val('');
$(sender).parent().siblings().find("input").prop('checked', false);
$(sender).parent().siblings().find("label").css("color", "#cccccc");
} else {
$(sender).parent().siblings().find("input").removeAttr('disabled');
$(sender).parent().siblings().find("label").css("color", "#000000");
}
}