数据是从表单提交过来的,表单没有提交,你能得到什么?解决方法<!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>test </title>
</head>
<body>
<form action="" method="post" name="ff">
<tr>
<td>
<input type="submit" name="submit" value="提交" />
<input name="ts" type="hidden" value="12121" />
</td>
</tr>
</form>
</body>
</html>
<?php
if(empty($_POST['ts']))echo "没数据";
else echo "取到数据";
echo $st;
?>点击提交按钮在看看!
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>test </title>
</head>
<body>
<form action="" method="post" name="ff">
<tr>
<td>
<input type="submit" name="submit" value="提交" />
<input name="ts" type="hidden" value="12121" />
</td>
</tr>
</form>
</body>
</html>
<?php
if(empty($_POST['ts']))echo "没数据";
else echo "取到数据";
echo $st;
?>点击提交按钮在看看!
改為:
if(empty($_POST['ts']))echo "没数据";
else echo "取到数据";
echo $_POST['ts'];
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>test </title>
</head>
<body>
<form action="" method="post" name="ff"> //这里action指向你的PHP文件,如果是当前文件,可以省掉action="".
<tr>
<td>
<input type="submit" name="submit" value="提交" />
<input name="ts" type="hidden" value="12121" />
</td>
</tr>
</form>
</body>
</html>
<?php
if(empty($_POST['ts']))echo "没数据";
else echo "取到数据";
echo $st; //同楼上,这里$st至少是在你写的这段代码里没有看到取值的情况,所以还是改为echo $_POST['ts'];为好
?>
body onload=aa()
寫個簡單的JS,對於樓主應該不是難事吧。
但對於樓主的想法,有點不解...
<!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>test </title>
</head>
<?php
$stInit = "12121";
?>
<body><form action="" method="post" name="ff">
<tr>
<input name="ts" type="hidden" value="<?php echo $stInit;?>" />
</tr>
</form>
</body>
</html>
<?php
if(empty($_POST['ts']))echo "没数据";
else {echo "取到数据";
echo $_POST['ts'];}
?>