中讀入我想讓我的CSS樣式從Javascript讀取一個變量並相應地設置CSS「top」值。例如:從Javascript設置一個PHP變量,並從<style>
$topPosition = false;
?>
<script language='JavaScript' type='text/javascript'>
function windowsHeightPixels() {
windowsHeight = $(window).height()
if (windowsHeight > 750) {
topPosition = false;
//set the $topPosition = false;
}
else {
topPosition = true;
//set the $topPosition = true;
}
}
windowsHeightPixels();
alert ("Height is " + windowsHeight + " Top Position is " + topPosition);
</script>
<style>
...
#fixedbutton {
position: fixed;
<?php if ($topPosition === false) : ?> top: 650px;
<?php else : ?> top: 127px;</p>
<?php endif; ?>
...
}
</style>
你可以看看這個鏈接http://stackoverflow.com/questions/5338972/how-to-include-php-code-in- css – theinarasu