我有三个 php 文件,可以通过 document.write() 调用...但是它们的'div Style'地方格式很乱。我想定期服用它们...
file1.php 120*240 像素:
document.write('
<?php
//some PHP codes
//echo style
echo"<style>#ps2{height:240;width:120;line-height:12px;font-family:tahoma;}
p a{text-decoration:none;}</style>";
echo("<div id=\"ps2\">");
//some PHP codes
echo"</div>";
?>
');
调用 php 文件:
<script language="javascript" src="file1.php"></script>
如果我在同一页面中调用 468*60 像素的 file2.php 和 125*125 像素的 file3.php ,如何修复所有代码分别显示和常规。
- 并且不仅在具有特定 css 的特定页面中单独且定期显示在任何页面中...谢谢
最佳答案
由于您是通过 http 加载文件,因此很容易拥有
html:
<script src="file.php?x=468&y=60"></script>
文件.php:
<?php
header('Content-type: text/javascript');
$html = <<<EOL
<style>
#ps2 {
width: {$_GET['x']},
height: {$_GET['y']}, etc....
EOL;
?>
document.write(<?php echo(json_encode($html)); ?>);
?>
关于javascript - 加载后的 document.write() 样式位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31755795/