小编Aga*_*oxi的帖子

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

可能重复:
如何将javascript变量放入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>
Run Code Online (Sandbox Code Playgroud)

这是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> …
Run Code Online (Sandbox Code Playgroud)

javascript php document.write

2
推荐指数
1
解决办法
985
查看次数

标签 统计

document.write ×1

javascript ×1

php ×1