jquery $.ajax $.post或者$.get如何提交checkbox的值

 
更多

form表单中包含有checkbox这种表单项的时候,直接提交处理很简单,只需在程序中处理结果即可。但使用jquery的ajax提交时该如何处理呢?下面通过一个例子说明一下。

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>jquery $.ajax $.post或者$.get如何提交checkbox的值</title>
<script type="text/javascript" src="http://www.phpernote.com/js/jquery.min.js";></script>
<script type="text/javascript">
function submitForm(){
	var str='';
	$("#phpernote>[type=checkbox]").each(function(){
		if($(this)[0].checked) {
			str+=$(this).val()+',';
		}
	});
	alert(str);
}
</script>
</head>
<body>
<form id="phpernote" action="javascript:submitForm();" method="post">
<input type="checkbox" value="1" />1<br />
<input type="checkbox" value="2" />2<br />
<input type="checkbox" value="3" />3<br />
<input type="checkbox" value="4" />4<br />
<input type="checkbox" value="5" />5<br />
<input type="submit" value="提交" />
</form>
</body>
</html>

思路很简单,就是把选中的值都取出来,通过循环处理成字符串,然后传递出去。

打赏

本文固定链接: https://www.cxy163.net/archives/3855 | 绝缘体

该日志由 绝缘体.. 于 2014年03月04日 发表在 未分类 分类下, 你可以发表评论,并在保留原文地址及作者的情况下引用到你的网站或博客。
原创文章转载请注明: jquery $.ajax $.post或者$.get如何提交checkbox的值 | 绝缘体
关键字: , , , ,

jquery $.ajax $.post或者$.get如何提交checkbox的值:等您坐沙发呢!

发表评论


快捷键:Ctrl+Enter