zl程序教程

您现在的位置是:首页 >  前端

当前栏目

jquery判断RadioButtonList和RadioButton中是否有选中项示例

jQuery 示例 判断 是否 选中 RadioButton radiobuttonlist
2023-06-13 09:15:06 时间
复制代码代码如下:

<preclass="html"name="code"><%--Body代码--%>
<div>
<asp:RadioButtonListID="RadioButtonList1"runat="server">
<asp:ListItemValue="A">a</asp:ListItem>
<asp:ListItemValue="B">b</asp:ListItem>
</asp:RadioButtonList>

<asp:RadioButtonID="RadioButton1"GroupName="RBtn"Text="男"runat="server"Checked="true"/>
<asp:RadioButtonID="RadioButton2"GroupName="RBtn"Text="女"runat="server"/>

<asp:ButtonID="Button1"runat="server"Text="Button"OnClientClick="Button1_ClientClick()"></asp:Button>
</div></pre>

复制代码代码如下:

<preclass="csharp"name="code"><%--Head代码--%>
<scriptlanguage="javascript"type="text/javascript"src="js/jquery-1.9.1.js"></script>
<scriptlanguage="javascript"type="text/javascript">

functionButton1_ClientClick()
{
alert($("input[name="RadioButtonList1"]:checked").val());//若都没有选中,则弹出“undefined”,若有选中的,则弹出对应的Value值
if(document.getElementById("RadioButton1").checked==true)//若RadioButton1被选中
{
alert($("#RadioButton1:checked").val());//弹出RadioButton1
alert($("#RadioButton2:checked").val());//弹出undefined
alert($("#RadioButton1:checked").val()=="RadioButton1");//弹出true
}
returnfalse;//暂时不用传到后台
}
</script>
</pre>