jquery 判断多组radio checkbox是否选中
最近要做一个问卷调查的小页面,需要判断用户是否每项都有选择,如果每个都挨个判断很苦逼,所以网上搜了搜,自己也总结了一下,写了一段小代码~哈哈,水平有限大家见谅。html代码就不上了,N多单选和多选框就对了。。。
function validate_all(){
var radioName = new Array();
$(":radio").each(function(){
radioName.push($(this).attr("name"));
});
$(":checkbox").each(function(){
radioName.push($(this).attr("name"));
});
radioName.sort();
$.unique(radioName);
$.each(radioName,function(i,val){
if(!checkRadio(val)){
alert("您还有未选择项,请选择,谢谢~");
return false;
}
});
}
function checkRadio(radioName){
return $("input[name="+radioName+"]:checked").val() == null ? false : true;
}
哈哈,其实就是获取所有radio和checkbox的name,sort()排完序后用unique去除重复,在each数组遍历每个name是否有选中值就ok啦~
jquery 判断多组radio checkbox是否选中的更多相关文章
- jQuery判断复选框checkbox的选中状态
通过jQuery设置复选框为选中状态 复选框 <input type="checkbox"/> 错误代码: $("input").attr(&quo ...
- [jQuery] 判断复选框checkbox是否选中checked
返回值是true/false method 1: $("#register").click(function(){ if($("#accept").get(0) ...
- jquery判断复选框checkbox是否被选中
jquery判断复选框checkbox是否被选中 使用is方法 //如果选中返回true //如果未选中返回false .is(':checked');
- Jquery Mobile下设置radio控件选中
问题: .html文件头部引入了: <script src="js/jquery.js"></script> <script src="js ...
- 判断有几个checkbox被选中
//判断是否有选中的checkbox的值是否为空 var number = $("input[type='checkbox']:checked").length; if(numbe ...
- jquery根据值设置radio和select选中状态
1.radio选中: $("input[name=test][value=34]").attr("checked",true);//value=34的radio ...
- Jquery使select、radio某项选中
select $("#class").find("option[value='123']").attr("selected",true); ...
- jQuery 判断多个 input checkbox 中至少有一个勾选
html ( 使用 TP 标签 ) : <volist name="health_tag" id="htag"> <input type=&q ...
- jQuery判断复选框是否被选中的3种方式
页面部分: <input type="checkbox" id="cbx" /><label for="cbx"& ...
随机推荐
- JDK动态代理例子
JDK动态代理的代理类必须实现于接口.如果要代理类,则使用CGLIB代理. 先定义一个接口: public interface Character { public void show(); } 接着 ...
- mysql 获取全局唯一值
在涉及数据库存储数据的时候,经常会遇到唯一值问题,有的是主键带来的限制,有的则是业务上的需要. 下面介绍几种唯一值的获取或者生产方法: 先建一个测试用的表tbl_user,有三个字段:Id.Name. ...
- ASP.NET MVC 4.0 学习1-C#基础语法
1,方法多載,相同的方法名稱,不同的參數類型.數量 class Program { static void Main(string[] args) { Program newObject = new ...
- pm2安装及常用命令
安装:npm install -g pm2 启动程序:pm2 start <app_name|id|all> 列举进程:pm2 list 退出程序:pm2 stop <app_nam ...
- [原]bochs+dos6.22汇编环境
1.下载安装bochs 下载MS-DOS http://files.cnblogs.com/allbymyself/DOS6.22.rar 下载Masm5.0 2.bochs配置 1)安装目录下的bx ...
- Java所有编码问题参考手册
一.编码基本知识 1.iso8859-1 ——属于单字节编码,最多能表示的字符范围是 0-255,应用于英文系列.比如,字母 'a' 的编码为0x61=97. 很明显,iso8859-1 编码表示的 ...
- Blog透视镜
Blog透视镜,提供了Blog代码示例,文章和教程,可以帮助你建置博客. 网站名称:Blog透视镜 网站地址:http://blog.openyu.org
- logstash 处理tomcat日志
[root@dr-mysql01 tomcat]# cat logstash_tomcat.conf input { file { type => "zj_api" path ...
- 是否需要手动执行DataContext的Dispose方法?
我们知道DataContext实现了IDisposable接口.在C#中,凡是实现了IDisposable接口的类,都推荐的使用using语句.如下: using (DataContext db = ...
- Can you find it? 分类: 二分查找 2015-06-10 19:55 5人阅读 评论(0) 收藏
Description Give you three sequences of numbers A, B, C, then we give you a number X. Now you need t ...