有2个RadioButtonLists:
Are you a minor?: oYes oNo
Do you wish a joint account?: oYes oNo
如果第一个问题的答案是肯定的,我想检测对第一个问题的回答,并使用jQuery函数将第二个问题的答案设置为yes。提前谢谢。
<asp:Label ID="lblMinfor" CssClass="boldIt" runat="server" Text="Is this account for a minor" Style="float: left; width: 200px;"></asp:Label><br />
<asp:RadioButtonList ID="rdlMinor" runat="server" RepeatDirection="Horizontal" Width="130px" Style="float: left;" BorderStyle="None" RepeatLayout="Flow" ()>
<asp:ListItem>Yes</asp:ListItem>
<asp:ListItem Selected="True">No</asp:ListItem>
</asp:RadioButtonList>
<asp:Label ID="lblJoint" CssClass="boldIt" runat="server" Text="Is this for a joint account?" Style="float: left; width: 200px;"></asp:Label><br />
<asp:RadioButtonList ID="rdlJoint" runat="server" RepeatDirection="Horizontal" Width="130px" Style="float: left;" BorderStyle="None" RepeatLayout="Flow">
<asp:ListItem>Yes</asp:ListItem>
<asp:ListItem Selected="True">No</asp:ListItem>
</asp:RadioButtonList>
答案 0 :(得分:11)
$('#<%=rdlMinor.ClientID %>').change(function() {
if($('#<%=rdlMinor.ClientID %> input:checked').val() == 'Yes')
{
$('#<%=rdlJoint.ClientID %>').find("input[value='Yes']").attr("checked", "checked");
}
});
答案 1 :(得分:4)
试试这段代码:
<script type="text/javascript">
$(document).ready(function() {
$("#<%=rdlMinor.ClientID%>").change(function()
{
var rbvalue = $("input[@name=<%=rdlMinor.ClientID%>]:radio:checked").val();
if(rbvalue == "Yes")
{
$('#<%=rdlJoint.ClientID %>').find("input[value='Yes']").attr("checked", "checked");
}
});
});
</script>
有关这些主题的更多信息:
JQuery Accessing the Client Generated ID of ASP.NET Controls