直接上代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>多项选择题</title> </head> <body> <p>以下哪些城市属于省会城市?</p> <form action="" method="post" name="form"> <input name="answer[]" type="checkbox" value="A" />广州<br> <input name="answer[]" type="checkbox" value="B" />成都<br> <input name="answer[]" type="checkbox" value="C" />北京<br> <input name="answer[]" type="checkbox" value="D" />福州<br> <input name="answer[]" type="checkbox" value="E" />重庆<br> <input name="answer[]" type="checkbox" value="F" />沈阳<br> <input name="send" type="submit" value="提交" /> </form> <?php if(isset($_POST['send'])) { $answer=$_POST['answer']; $choice=" "; for($i=0;$i<count($answer);$i++) $choice.=$answer[$i]; if($choice =='ABDF') show('恭喜你,答对了!'); else show('很遗憾,重新答!'); } function show($message) { echo"<script>alert('$message')</script>"; } ?> </body> </html>
在浏览器上运行出现以下界面:
我们选择好后点击提交:
标签:PHP,哪些,城市,多选题,属于,省会 From: https://www.cnblogs.com/0625wangqian/p/18220410