qq_18136213
2017-02-25 16:02
采纳率: 33.3%
浏览 3.7k
已采纳

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=gb2312" />
<title>计算器</title>
<script type="text/javascript">
//document.getElementById("sub1").submit();
function setval(){
var gd = document.getElementById("gaodu").value;
var kd = document.getElementById("kuandu").value;
var sl = document.getElementById("shuliang").value;
if(gd=="")
document.getElementById("gaodu").value=1600;
if(kd=="")
document.getElementById("kuandu").value=600;
if(sl=="")
document.getElementById("shuliang").value=1;
}
</script>
</head>
<?php  
     $gaodu=$_GET["gaodu"];
     $kuandu=$_GET["kuandu"];
     $shuliang=$_GET["shuliang"];
?>     
<body onload="setval()">  
<form action="" id="sub1">  
<input name="gaodu" type="text" id="gaodu" onchange="tijiao()" value="<?php echo $gaodu ?>"> 
<input name="kuandu" type="text" id="kuandu" onchange="tijiao()" value="<?php echo $kuandu ?>">
<input name="shuliang" type="text" id="shuliang" onchange="tijiao()" value="<?php echo $shuliang ?>"> 
<input name="sub" id="sub" type="submit"  value="计算">
</form>
<table width="200" border="1">
  <tr>
    <td><?php echo $gaodu+$kuandu ?></td>
    <td><?php echo $gaodu-$kuandu ?></td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
</table>
</body>  
</html>

以上代码是想做一个特定功能的计算器,为了初始化页面数据,用js设置了表单默认值,但是页面加载时无法自动计算结果(试过js代码onload提交表单,但是页面会不停的刷新)请教提交表单时只刷新数据不刷新页面的办法,谢谢!

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

9条回答 默认 最新

相关推荐 更多相似问题