Adding attribute to body tag with PHP
I'm trying to add the bgcolor
attribute to the body
tag with PHP.
Using getElement()
and setAttribute()
won't work in PHP.
Does anyone know a solution?
I want to change the background color of the body with PHP, so any other solutions using PHP would be great too.
Edit: For an assignment that's way outdated we HAVE to use PHP to change the backgroundcolor and we need to use bgcolor. With a POST form with some radiobuttons and a Submit button we need to change the bgcolor. Up to this I used echo to ADD a tag after there is a tag already. Any ideas on that?
Edit2: I tried to echo the in the bgcolor attribute, but that seems to stop the full page from loading, so that doesn't work unfortunately.
PHP is server side! If you want to do it with php simple echo it like this
<?php echo '<body style="background-color:#000">'; ?>
otherwise you will need to do it in javascript with
document.getElementsByTagName('body')[0].style.backgroundColor = '#000';
hope that help
A simple solution is to inject this somewhere in your html:
<style type="text/css">
body {
background-color: <?php echo $color; ?> !important;
}
</style>
Then before this code is run, define $color
to hold a color value like #cccccc
.
Well, actually you shoudn't use bgcolor anymore. Instead, give a css style to the body tag:
<?php
$color = "#004422";
?>
<body style="background-color:<?php echo $color; ?>">
<!-- CONTENT -->
</body>
链接地址: http://www.djcxy.com/p/87670.html
上一篇: 如何突出显示我的文字
下一篇: 使用PHP为body标签添加属性