在file1.php
,我执行file2.php
与文档对象混乱
<form action="file2.php" method="POST">
在文件2,我想从文件1访问HTML元素,但它们的文档对象是不同的。
如何从file2中访问file1的元素?
在file1.php
,我执行file2.php
与文档对象混乱
<form action="file2.php" method="POST">
在文件2,我想从文件1访问HTML元素,但它们的文档对象是不同的。
如何从file2中访问file1的元素?
好而不是使用JavaScript就可以访问你通过PHP的$_POST功能所需要的,所以如果你有元素名和密码,你可以用访问它们:
$_POST['name'];
$_POST['password'];
所以像这样的file2.php:
<?php
if(array_key_exists('submit', $_POST))
{
$username = $_POST['name'];
$password = $_POST['password'];
echo("Hello $username, your password is $password");
}
?>
这那张file1.php的假设看起来像:
<form action="file2.php" method="post">
Username:
<input type="text" name="name" />
<br />
Password:
<input type="password" name="password" />
<br />
<input type="submit" name="submit" />
</form>
为什么你不试试在file2.php中隐藏你仍然需要的元素?
只需使用php在file2.php中再次渲染它们,并通过CSS隐藏它们,然后通过javascript轻松访问它们。
太棒了,这是我需要的答案! – wucnuc 2009-06-26 16:05:30