<!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>
<center>
<h1>欢迎使用试卷生成系统</h1>
<br><br><br><br>
<font color="#FF0000"><h3>请选择试卷要求</h3></font>
<br><br><br><br>
<form id="form1" name="form1" method="post" action="jieshou.php">
<table>
<tr>
<td> <input type="checkbox" name="j1" value=1>
是否有负数
<br><br>
</td>
</tr>
<tr>
<td><input type="checkbox" name="j2" value=2>
是否有余数<br><br>
</td>
</tr>
<tr>
<td><input type="checkbox" name="j3" value=3>
是否有乘除<br><br>
</td>
</tr>
<tr>
<td>
计算范围:
</td>
<td>
<input type="text" name="j6" width="50" style="30px" onkeyup="this.value=this.value.replace(/D/g,'')" onafterpaste="this.value=this.value.replace(/D/g,'')">
--
<input type="text" name="j7" style="30px" width="50" onkeyup="this.value=this.value.replace(/D/g,'')" onafterpaste="this.value=this.value.replace(/D/g,'')">
<br><br>
</td>
</tr>
<tr>
<td colspan="3" align="center"><input type="submit" value="生成试卷"、><!--注册按钮-->
<input type="reset" value="取消"><!--取消按钮-->
</tr>
</table>
</form>
</center>
</body>
</html>
运算。php
<!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>
<?php
error_reporting(E_ALL^E_NOTICE^E_WARNING^E_DEPRECATED);
if($_POST['j6']==''||$_POST['j7']=='')
{
echo"<script>alert('请输入范围');</script>";
echo "<script language='javascript'>";
echo " location='xz.html ';";
echo "</script>";
exit;
}
else if($_POST['j6']>$_POST['j7'])
{
echo "<script>alert('范围输入错误');</script>";
echo "<script language='javascript'>";
echo " location='xz.html ';";
echo "</script>";
exit;
}
$j1=array();
$i=1;
for(;$i<=30;$i+=1)
{
if($_POST['j3']==false)
{
$a1=array(1 =>rand($_POST[j6],$_POST[j7]),2 =>rand($_POST[j6],$_POST[j7]),3 =>rand(1,2));
}
else
{
$a1=array(1 =>rand($_POST[j6],$_POST[j7]),2 =>rand($_POST[j6],$_POST[j7]),3 =>rand(1,4));
}
$j1[$i]=$a1;
if($_POST['j1']==false&&$a1[3]==2)
{
if($j1[$i][1]<$j1[$i][2])
{
$q=$j1[$i][1];
$j1[$i][1]=$j1[$i][2];
$j1[$i][2]=$q;
}
}
if($j1[$i][3]==1)
{
$j1[$i][4]=$j1[$i][1]+$j1[$i][2];
}
if($j1[$i][3]==2)
{
$j1[$i][4]=$j1[$i][1]-$j1[$i][2];
}
if($j1[$i][3]==3)
{
$j1[$i][4]=$j1[$i][1]*$j1[$i][2];
}
if($j1[$i][3]==4&&$_POST['j2']==false)
{
$p=$j1[$i][1]*$j1[$i][2];
$j1[$i][4]=$j1[$i][1];
$j1[$i][1]=$p;
}
if($j1[$i][3]==4&&$_POST['j2']==true)
{
$j1[$i][4]=(int)($j1[$i][1]/$j1[$i][2]);
$j1[$i][5]=$j1[$i][1]%$j1[$i][2];
}
}
echo $_POST['j3'];
?>
<center>
<form id="form2" name="form2" method="post" action="jieshou.php">
<table>
<?php
for($i=1;$i<30;$i+=2)
{
?>
<tr>
<td>
<b>
<h4> <?php
echo $j1[$i][1];
echo " ";
if($j1[$i][3]==1)
{echo '+';}
else if ($j1[$i][3]==2)
{echo '-';}
else if ($j1[$i][3]==3)
{echo '*';}
else if ($j1[$i][3]==4)
{echo '/';}
echo " ";
echo $j1[$i][2];
echo " ";
echo '=';
echo " ";
?>
<input type='text' name=<?php $i ?> value=<?php $i+1 ?> width="50" style="30px">
</b>
<?php
if($j1[$i][3]==4&&$_POST['j2']==true)
{
echo "......";
?>
<input type='text' style="30px" name=<?php $i+1 ?> value=<?php $i+1 ?> >
<?php
}
?>
<b>
</td>
<td>
<?php
echo " ";
echo $j1[$i+1][1];
echo " ";
if($j1[$i+1][3]==1)
{echo '+';}
else if ($j1[$i+1][3]==2)
{echo '-';}
else if ($j1[$i+1][3]==3)
{echo '*';}
else if ($j1[$i+1][3]==4)
{echo '/';}
echo " ";
echo $j1[$i+1][2];
echo " ";
echo '=';
echo " ";
?>
<input type='text' style="30px" name=<?php $i+1 ?> value=<?php $i+1 ?> >
<?php
if($j1[$i+1][3]==4&&$_POST['j2']==true)
{
echo "......";
?>
<input type='text' style="30px" name=<?php $i+1 ?> value=<?php $i+1 ?> >
<?php
}
?>
</b>
</h4>
</td>
</tr>
<?php
}
?>
<tr>
<td>
<input type="submit" value="提交">
</td>
<td>
<input type="reset" value = "取消">
</td>
<td>
<input type="button" value = "打印" onClick="isOk();"/>
</td>
</center>
<script>
function isOk(){
if(confirm('是否开始打印?'))
{
window.print();
}
else
{
return false;
}
}
</script>
</td>
</tr>
</table>
</form>
</body>
</html>
设计思路:
1,建立xz.html,建立表单选择运算的要求,并传递到yunsuan.php
2.在yunsuan.php中获取表单数据,用for循环产生随机数;
3.根据随机数来决定运算符号和数据,
4.用for循环建立表单输出运算题
5.利用window.print打印运算题