Home  >  Article  >  Web Front-end  >  c# JQurey implements getting the values ​​of radio and checkbox

c# JQurey implements getting the values ​​of radio and checkbox

PHPz
PHPzOriginal
2016-05-16 16:29:211494browse

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 = "性别:" + $(&#39;input:radio[name = "sex"]:checked&#39;).val();
var shuzu = [];
$(&#39;input:checkbox[name = "aihao"]:checked&#39;).each(function () {//each每个
shuzu.push($(this).val());//给数组赋值
});
window.alert(str1 + &#39;\n&#39; + str2 + &#39;\n&#39; + "爱好:" + 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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn