php让checkbox复选框初始选中
php让checkbox复选框初始选中,很常用的功能,备忘下:
代码如下:
<metahttp-equiv="Content-Type"content="text/html;charset=UTF-8"/><?php$arr=array(0=>array('id'=>100,'title'=>'京东'),1=>array('id'=>200,'title'=>'天猫'),2=>array('id'=>300,'title'=>'苏宁'));$arrId=array(100,300);if(isset($_POST['mall'])){echo'<pre/>';print_r($_POST['mall']);exit();}?><formaction=""method="post"><?phpforeach($arras$key=>$value){?><?phpif(in_array($value['id'],$arrId)){?><inputtype="checkbox"name="mall[]"value="<?phpecho$value['id']?>"checked><?phpecho$value['title']?><?php}else{?><inputtype="checkbox"name="mall[]"value="<?phpecho$value['id']?>"><?phpecho$value['title']?><?php}?><?php}?><inputtype="submit"value="提交"/></form>
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。