我想在一个 PHP 变量中设置窗口宽度(通过 JavaScript 获取)并用它来描述 div 容器的属性,但是下面的代码不起作用...
<?php
header("Content-type: text/css; charset: UTF-8"); // Parsing CSS zu PHP
echo "<script type='text/javascript'>
if(typeof(window.innerWidth) !== 'number') {
if(document.documentElement.clientWidth !== 0) {
width = document.documentElement.clientWidth;
height = document.documentElement.clientHeight;
}
else {
width = document.body.clientWidth;
height = document.body.clientHeight;
}
}else {
width = window.innerWidth;
height = window.innerHeight;
}
$cwidth = document.write(width);
</script>";
?>
@charset "UTF-8";
#container
{
width: <?php echo $cwidth . 'px'; ?>;
}
问候