使用JQuery获取被选中的checkbox的value值
上网查了一下,感觉一些人回答得真的是不知所云,要么代码不够简便。或者是有些想装逼成分等。
以下为使用JQuery获取input checkbox被选中的值代码:
<html>
<head>
<meta charset="gbk">
<!-- 引入JQuery -->
<script src="jquery-1.3.1.js" type="text/javascript"></script>
</head>
<body>
<input type="checkbox" value="橘子" name="check">橘子1</input>
<input type="checkbox" value="香蕉" name="check">香蕉1</input>
<input type="checkbox" value="西瓜" name="check">西瓜1</input>
<input type="checkbox" value="芒果" name="check">芒果1</input>
<input type="checkbox" value="葡萄" name="check">葡萄1</input>
<input type="button" value="方法1" id="b1">
<input type="button" value="方法2" id="b2">
</body>
<script>
//方法1
$("#b1").click(function(){
//$('input:checkbox:checked') 等同于 $('input[type=checkbox]:checked')
//意思是选择被选中的checkbox
$.each($('input:checkbox:checked'),function(){
window.alert("你选了:"+
$('input[type=checkbox]:checked').length+"个,其中有:"+$(this).val());
});
});
//方法2
$("#b2").click(function(){
$.each($('input:checkbox'),function(){
if(this.checked){
window.alert("你选了:"+
$('input[type=checkbox]:checked').length+"个,其中有:"+$(this).val());
}
});
});
</script>
</html>
使用JQuery获取被选中的checkbox的value值的更多相关文章
- JQuery获取被选中的checkbox的value值
文章源头:http://www.cnblogs.com/td960505/p/6123510.html 以下为使用JQuery获取input checkbox被选中的值代码: <html> ...
- 使用JQuery获取被选中的checkbox的value值 以及全选、反选
以下为使用JQuery获取input checkbox被选中的值代码: <html> <head> <meta charset="gbk"> & ...
- jquery获取所有选中的checkbox的ID
//获取所有选中的CheckBox的id function getCheckBox() { var spCodesTemp = ""; $("input:checkbox ...
- jquery获取所有选中的checkbox
获取所有name为spCodeId的checkbox var spCodesTemp = ""; $("input:checkbox[name=spCodeI ...
- jQuery获取radio选中后的文字
原文链接:http://blog.csdn.net/zhanyouwen/article/details/51393216 jQuery获取radio选中后的文字转载 2016年05月13日 10:3 ...
- element ui 表格提交时获取所有选中的checkbox的数据
<el-table ref="multipleTable" :data="appList" @selection-change="changeF ...
- jq获取被选中的option的值。jq获取被选中的单选按钮radio的值。
温故而知新,一起复习下jq的知识点. (1) jq获取被选中的option的值 <select id="select_id"> <option value=&qu ...
- jQuery获取Select选中的Text和Value,根据Value值动态添加属性
语法解释:1. $("#select_id").change(function(){//code...}); //为Select添加事件,当选择其中一项时触发2. var chec ...
- jQuery获取Select选中的Text和Value,根据Value值动态添加属性等
语法解释:1. $("#select_id").change(function(){//code...}); //为Select添加事件,当选择其中一项时触发2. var ch ...
随机推荐
- leetcode解题报告(1):Remove Duplicates from Sorted Array
描述 Given a sorted array, remove the duplicates in place such that each element appear only once and ...
- [Luogu] 贪婪大陆
https://www.luogu.org/problemnew/show/P2184 区间修改时只需修改区间端点的numl或numr值 区间查询x-y只需用1-y的numr - 1-(x - 1)的 ...
- 解决zabbix的cannot allocate shared memory of size错误
问题状态:zabbix_server 不能启动,系统CentOS 6.7 原因分析:这是因为内核对share memory的限制造成的. 用到如下命令ipcs [-m|l|a],sysctl [-a| ...
- laotech老师唠科mac 深入浅出MAC OS X ceshi ruguokeyi
laotech老师唠科mac 深入浅出MAC OS X http://study.163.com/plan/planLearn.htm?id=1637004#/learn/resVideo?lesso ...
- 2016"百度之星" - 初赛(Astar Round2A)1005 BD String(HDU5694)——找规律、字符串对称、分治
分析:按照题目所给的意思每次处理得到的新的字符串都是具有高度对称性的,举个例子,如题目所给的第三个字符串,最中间的是B然后两边分散开去,一边是B的话另外一边关于这个中心对称的那个位置一定是D,反过来同 ...
- Django 配置实用bootstrap
1.下载bootstrap代码包. 2.在目录下创建static文件夹,将bootstrap文件夹移动到static文件夹内,编辑settings.py: 最后添加如下(文件末尾): STATIC_U ...
- python 中对象is和==是怎么比较的
Python中的对象包含三要素:id.type.value.其中id用来唯一标识一个对象,type标识对象的类型,value是对象的值.is判断的是a对象是否就是b对象,是通过id来判断的.==判断的 ...
- mySQL 插入,更新和删除数据
插入数据: 语法: INSERT INTO table_name ( field1, field2,...fieldN ) VALUES ( value1, value2,...valueN ); 如 ...
- js 删除 按钮所在的行
<body> <table id="delte"> <caption>简易购物车</caption> <tr> < ...
- <frameset>和<body>不能共用
frameset 定义: frameset 元素可定义一个框架集.它被用来组织多个窗口(框架).每个框架存有独立的文档.在其最简单的应用中,frameset 元素仅仅会规定在框架集中存在多少列或多少行 ...