Document.write()加载后的样式位置


document.write() style position after load

我有三个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>

如果我调用 file_2 .php与468*60像素和 file_3 .php与125*125像素在同一页面,我怎么能修复所有代码分别显示和规则。

  • 和显示在任何页面单独和规则,不仅在特定的页面与特定的css…由于

由于您通过http加载文件,因此很容易使用

html:

<script src="file.php?x=468&y=60"></script>

file.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)); ?>);

?>