如何从HTML Div中的.java文件显示源代码



我正在使用HTML,PHP,JS和我准备网站,我需要将源代码文件(例如.java,.xml(显示为我网站的一部分。

就像其他任何文本文件一样。源代码只是文本。带有源代码的文件只是文本文件。

http://php.net/manual/en/function.file-get-contents.php

http://php.net/manual/en/function.fopen.php

http://php.net/manual/en/function.fread.php

$file = file_get_contents('./people.txt', FILE_USE_INCLUDE_PATH);

<div id="sourcecode"> <?= $file ?> </div>

您可以使用file_get_contents

http://php.net/manual/en/function.file-get-contents.php

您说的是您在网站中使用的JS。这是使用jQuery的解决方案。希望这将帮助您将源代码文件显示到HTML Div中。

<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Testing</title>
</head>
<body>
    <div id="include"></div>
    <a style="display:none;" id="link" href="javascript:void(0);">Click Test Link</a>
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
    <script type="text/javascript">
        $("#link").click(function() {
            $("#include").load("from.html");
        });
        $(function() {
            $("#link").trigger("click");
        });
    </script> 
</body>

`

最新更新