jquery判断checkbox是否选中

 
更多

使用jquery判断一组checkbox是否选中,以及如何如何使用js提交checkbox选中的值。具体代码如下:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="http://www.phpernote.com/js/jquery.min.js"></script>
<script type="text/javascript">
$(function(){
	$('input[type=button]').click(function(){
		var result=new Array(),str='';
		$('input[name="username[]"]:checked').each(function(){
			result.push($(this).val());
		});
		var str=result.join(',');
		if(str==''){
			alert('没有选中任何选项!');
			return false;
		}
		alert(result);
		//提交选项值
		$.post('http://www.phpernote.com/',{username:str},function(){});
	});
});
</script>
<title>jquery判断checkbox是否选中示例</title>
</head>
<body>
<input name="username[]" type="checkbox" value="taobao" />淘宝
<input name="username[]" type="checkbox" value="google" />谷歌
<input name="username[]" type="checkbox" value="phpernote" />phper笔记
<br />
<input type="button" value="提交" />
</body>
</html>
打赏

本文固定链接: https://www.cxy163.net/archives/3835 | 绝缘体-小明哥的技术博客

该日志由 绝缘体.. 于 2014年04月03日 发表在 go, html, javascript, PHP, 编程语言 分类下, 你可以发表评论,并在保留原文地址及作者的情况下引用到你的网站或博客。
原创文章转载请注明: jquery判断checkbox是否选中 | 绝缘体-小明哥的技术博客
关键字: , , , ,

jquery判断checkbox是否选中:等您坐沙发呢!

发表评论


快捷键:Ctrl+Enter