js限制checkbox选项个数 php获取多个checkbbox的方法_PHP教程

WBOY
发布: 2016-07-20 11:13:17
原创
907 人浏览过

1,js限制checkbbox勾选个数的代码:

<!DOCTYPE HTML <span PUBLIC</span> "-//W3C//DTD HTML 4.01 Transitional//EN" 
"http://www.w3.org/TR/html4/loose.dtd"> 
<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"> 
<title>限制复选框选择的数量-www.jbxue.com-脚本学堂</title> 
<script type="text/javascript" > 
<span function</span> <span checkDate</span><span (n){ 
</span><span var</span> checkedCount=0<span ; 
</span><span for</span>(<span var</span> i=0;i<myForm.course.length ;i ++<span ){ 
</span><span if</span>(myForm.course[i].<span checked){ 
checkedCount</span>++<span ;

} 
} 
</span><span if</span>(checkedCount><span n){

alert(</span>"不能选超过三门课程"<span );

</span><span return</span> <span false</span><span ;

} 
}

</span></script> 
</head> 
<body> 
<form name="myForm" method="post" id="myForm" action="test.php"><span  
请选择这学期的选课(最多三门):</span><br> 
<input type="checkbox" name="course[]" value="语文" onClick="return checkDate(3)">语文<br> 
<input type="checkbox" name="course[]" value="数学" onClick="return checkDate(3)">数学<br> 
<input type="checkbox" name="course[]" value="英语" onClick="return checkDate(3)">英语<br> 
<input type="checkbox" name="course[]" value="化学" onClick="return checkDate(3)">化学<br> 
<input type="checkbox" name="course[]" value="物理" onClick="return checkDate(3)">物理<br> 
<input type="checkbox" name="course[]" value="政治" onClick="return checkDate(3)">政治<br> 
<input type="submit" value="提交"> 
<input type="reset" value="取消"> 
</form> 
</body> 
</html>
登录后复制

<?<span php
</span><span /*</span><span *
* 获取checkbox的值
* edit by www.jbxue.com
</span><span */</span>
<span $course</span>=<span $_POST</span>['course'<span ];
</span><span for</span>(<span $i</span>=0;<span $i</span><<span count</span>(<span $course</span>);<span $i</span>++<span ) 
{ 
</span><span if</span>(<span $course</span>[<span $i</span>]!=""<span ) 
{
</span><span echo</span> <span $course</span>[<span $i</span>]."<br/>"<span ;
} 
} 
</span>?>
登录后复制

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/440387.htmlTechArticle1,js限制checkbbox勾选个数的代码: !DOCTYPE HTML "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd" html head meta http-equiv="Content-Type"...
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板