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"& ...
随机推荐
- mysql中查看字符集的cmd指令
参看下面链接:http://blog.chinaunix.net/uid-20180960-id-1972668.html
- c++中的名字查找
参看下面链接:<C++中的名字查找>
- linux下python3连接mysql数据库
python语言的3.x完全不向前兼容,导致我们在python2.x中可以正常使用的库,到了python3就用不了了.比如说mysqldb 1.安装pymysql pymysql就是作为python3 ...
- [Head First Python]5. summary
1- "原地"排序-转换后替换 >>> list = [2,1,3] >>> list.sort() >>> list [1, ...
- Python学习笔记一,输入输出
输出:用print()在括号中加上字符串,就可以向屏幕上输出指定的文字.比如输出'hello, world',用代码实现如下>>>print('hello,world') 也可以是多 ...
- Python中def的用法
def定义了一个模块的变量,或者说是类的变量.它本身是一个函数对象.属于对象的函数,就是对象的属性. def func(): return 2print func() # 1func = 5pr ...
- python----抽象类
#!/usr/local/python3.5/bin/python3.5 ####实现方法一 class Supper(object): def delegate(self): self.action ...
- leiningen安装记录
Leiningen是Clojure项目管理工具Leiningen is the easiest way to use Clojure,官网:http://leiningen.org/ 1:首先下载Le ...
- hash算法-time33算法
http://my.oschina.net/freegeek/blog/325531 http://www.cnblogs.com/napoleon_liu/articles/1911571.html ...
- SQL Server 2008空间数据应用系列五:数据表中使用空间数据类型
原文:SQL Server 2008空间数据应用系列五:数据表中使用空间数据类型 友情提示,您阅读本篇博文的先决条件如下: 1.本文示例基于Microsoft SQL Server 2008 R2调测 ...