【php开源代码栏目提醒】:网学会员为广大网友收集整理了,18_11.php,希望对大家有所帮助!
<?php
header('Content-Type:text/html;charset=GB2312');
//处理客户端数据的函灵敏
function do_post($name,$birthday){
$now = date("Y-m-d");
$age = $now - $birthday;
return $name."今年".$age."岁";
}
//引用SAJAX代码
require("18_9.php");
//初始化SAJAX
sajax_init();
sajax_export("do_post");
sajax_handle_client_request();
?>
<!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>SAJAX与表单</title>
<script>
<?
sajax_show_javascript();
?>
function do_post_cb(z) {
//返回的数据中如果存在中文字符,可以使用JavaScript的unescape()进行解码
document.getElementById("age").value = z;
}
function do_post() {
//处理表单变量
var name,birthday;
name = document.getElementById("name").value;
birthday = document.getElementById("birthday").value;
//把界面处理函数与表单变量,作为参数提供给回调函数
x_do_post(name,birthday,do_post_cb);
}
</script>
</head>
<body>
<form id="form1" name="form1" method="post" action="">
<label>:
<input type="text" name="name" id="name" />
</label><br>
<label>生日:
<input type="text" name="birthday" id="birthday" />示例:1990-11-23
</label><br>
<label>
<input type="button" name="Submit" value="计算年龄" onclick="do_post();" />
</label><br>
<label>结果:
<input name="age" type="text" id="age" />
</label>
</form>
</body>
</html>
上一篇:
18_10.php
下一篇:
试析影响公路路面平整度的因素及应采取的施工措施