在file1.php
中,我使用
file2.php
<form action="file2.php" method="POST">
在file2中,我想从file1访问html元素,但它们的文档对象是不同的。
如何从file2中访问file1的元素?
答案 0 :(得分:1)
而不是使用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>
答案 1 :(得分:0)
为什么不尝试在file2.php中隐藏你仍然需要的元素?。
在file2.php中使用php再次渲染它们,然后通过CSS隐藏它们,然后通过javascript轻松访问它们。