欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

checkbox全选 和获取值

程序员文章站 2022-06-12 16:02:48
...

<script type='text/javascript'>
//全选
function checkAllChkBox(boolvalue,formid)
{
	var name = formid+'[]';
	var ochkForm	= document.getElementById(formid);
	var ochkBoxes	= document.getElementsByName(name);
	try {
		if(ochkBoxes.length>0)
		{
			for(var i=0;i<ochkBoxes.length;i++)
			{
				ochkBoxes[i].checked = boolvalue;
			}
		}
		else
		ochkBoxes.checked = boolvalue;
	}
	catch (e) {}
}
//获取选取值
function getchkbox(fid)
{
	var name = fid+'[]';
	var ochkForm	= document.getElementById(fid);
	var ochkBoxes	= ochkForm[name];
	if (ochkBoxes == undefined)
	{
		bangding();
		return;
	}	
	var strval = "";
	
	var biaoyang = jQuery('#biaoyang').val();
	var iLen = ochkBoxes.length;
	var iLenval = 0;
	for(var i=0;i<iLen;i++)
	{
		if (ochkBoxes[i].checked == true)
		{
			strval = strval+'&'+ochkBoxes[i].value;
			iLenval++;
		}	
	}
	if (iLenval > 0)
	{
		alert("你将表扬:"+strval+":"+biaoyang);
	}
	else
	{
		alert("您未选择该分组下任何用户");
	}	
}
</script>
 <div class="quanxuan"><input name="" type="checkbox" onclick="checkAllChkBox(this.checked,'check1')" value=""/> 全选</div>
		 <form name="check1" id="check1">
		
		<div class="hiuyuan clearfix">
			<div class="imgDiv">
				<a href="#"><img src="/images/adorn/b_00.gif" width="50" height="50" alt="" /></a><input type="checkbox" name="check1[]"  value='1287464960' class="input"/><a href="#">张三</a>
			</div>
			<div class="imgDiv">
				<a href="#"><img src="/images/adorn/b_00.gif" width="50" height="50" alt="" /></a><input type="checkbox" name="check1[]" value="1287464960" class="input"/><a href="#">跟对跟对方给</a>
			</div>
			<div class="imgDiv">
				<a href="#"><img src="/images/adorn/b_00.gif" width="50" height="50" alt="" /></a><input type="checkbox" name="check1[]" value="1287464960" class="input"/><a href="#">跟跟方给</a>
			</div>
			<div class="imgDiv">
				<a href="#"><img src="/images/adorn/b_00.gif" width="50" height="50" alt="" /></a><input type="checkbox" name="check1[]" value="1287464960" class="input"/><a href="#">李四</a></a>
			</div>
			<div class="imgDiv">
				<a href="#"><img src="/images/adorn/b_00.gif" width="50" height="50" alt="" /></a><input type="checkbox" name="check1[]" value="1287464960" class="input"/><a href="#">跟对跟对方给</a>
			</div>

		</div>
		</form>
 
相关标签: jQuery JavaScript