>  기사  >  백엔드 개발  >  js限制checkbox选项个数 php获取多个checkbbox的方法_PHP教程

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

WBOY
WBOY원래의
2016-07-20 11:13:17890검색

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"...
성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.