gpt4 book ai didi

php - 为什么 document.write + echo 不起作用?

转载 作者:行者123 更新时间:2023-11-29 17:19:38 25 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
how to put javascript variable in php echo

我对 PHP 有疑问。我想在 JavaScript 中使用 PHP 变量。但是,它不起作用! $doccontent 只显示一次!这里是Test.php(给定页面参数,例如Test.html):

<!DOCTYPE html>
<html>
<head>
<title>Test</title>
<?php
$page = $_GET["page"];
$doc = new DOMDocument();
$doc->loadHTMLFile($page);
$doc->formatOutput = true;
$contentnode = $doc->getElementById('content');
$doccontent = new DOMDocument();
$doccontent->appendChild($doccontent->importNode($contentnode, true));
$doccontent = $doccontent->saveHTML();
?>
</head>
<body>
<?php
echo $doccontent;
?>
<script type="text/javascript">
document.write("<?php echo $doccontent;?>");
</script>
</body>
</html>

这里是Test.html:

<!DOCTYPE html>
<html>
<head>
<title>Hey</title>
<link rel="stylesheet" type="text/css" href="Edit.css">
</head>
<body>
<button id="admin"><a href="Edit.php?page=Edit.html">Edit</a></button>
<h1>Automatica</h1>
<div id="content">
<h2>Header 1.1</h2>
<p>Test</p>
<h3>Header 1.1.1</h3>
<p>Test</p>
<h3>Header 1.1.2</h3>
<p>Test</p>
<p>Test</p>
<h4>Header 2.0.0.1</h4>
<p>Test</p>
</div>
</body>
</html>

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com