这是我的HTML,我称之为外部PHP
<!DOCTYPE html>
<html>
<body>
<h1>My First Heading</h1>
<script src="index.php"></script>
<p>My first paragraph.</p>
</body>
</html>
和我的PHP脚本
<?
$strFileName = "poom.bis";
$objFopen = fopen($strFileName, 'r');
if ($objFopen) {
while (!feof($objFopen)) {
$file = fgets($objFopen, 4096);
// echo $file;
echo "document.writeln('$file'+);";
}
fclose($objFopen);
}
$test = "hello world";
echo "document.writeln(
'<ul>'+
'<li>.$test.</li>'+
'<li>test2</li>'+
'<li>test3</li>'+
'</ul>'
);";
?>
多次使用document.write时出错
我该怎么做才能解决这个问题
请建议
PS。使用echo“document.writeln('$ file'+);”;一次没有错误并显示结果
答案 0 :(得分:0)
第一个错误:你的行
echo "document.writeln('$file'+);";
应该是
echo "document.writeln('$file');";
(没有加号)。还要确保文件poom.bis
不包含换行符,即使最后也不包含换行符。如果是这样,你必须将它们剥离(trim()
)。
第二个错误 (直到您编辑它)使用document.writeIn
(不存在)而不是document.writeln
(确实如此)。
经过测试,确实有效。
此外,当我遇到它时,因为您询问了如何解决此问题的建议:查看浏览器的错误控制台并尝试调试它。
答案 1 :(得分:-1)
echo '<script>document.writeln(';
echo '"<ul><li>test1</li><li>test2</li><li>test3</li></ul>"';
echo ');</script>';
;