This article mainly introduces the method of obtaining the value of radio and checkbox using c# combined with JQurey. The code is shared with everyone. Friends who need it can refer to it.
Without further ado, let’s go straight to the code:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Web2.aspx.cs" Inherits="Chapter2.Web2" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> <script src="jquery-1.8.0.js"></script> <script type="text/javascript"> $(function () { $("#sub").click(function () { var str1 = "张三:" + $("#name").val(); var str2 = "性别:" + $('input:radio[name = "sex"]:checked').val(); var shuzu = []; $('input:checkbox[name = "aihao"]:checked').each(function () {//each每个 shuzu.push($(this).val());//给数组赋值 }); window.alert(str1 + '\n' + str2 + '\n' + "爱好:" + shuzu); }); }); </script> </head> <body> <form id="form1" runat="server"> 姓名:<input type="text" id="name" /><br /> 性别:<input type="radio" id="nan" name="sex" checked="" value="男" />男<input type="radio" id="nv" name="sex" value="女" />女<br /> 爱好:<input type="checkbox" />游泳 <input type="checkbox" name="aihao" value="爬山" />爬山 <input type="checkbox" name="aihao" value="打球" />打球 <input type="checkbox" name="aihao" value="骑车" />骑车 <input type="checkbox" name="aihao" value="阅读" />阅读 <input type="checkbox" name="aihao" value="聊天" />聊天<br /> <input type="button" id="sub" value="提交" /><input type="button" id="b" value="重置" /> </form> </body> </html>
The code is very concise, but very practical. Friends can rewrite it according to their own project needs and use it.
The above is the entire content of this chapter. For more related tutorials, please visit jQuery Video Tutorial, C# Video Tutorial!