그래서 특정 시간대에 배경색을 변경하는 간단한 함수를 작성하려고하지만 뭔가 올바르게 작동하지 않습니다.PHP : 특정 시간대에 CSS 속성 변경
PHP를 실행할 때 페이지의 배경색이 비어 있고 HTML에 background-color: ;
이 있습니다. blue
또는 black
속성에 도달하지 못하여 그 이유를 알고 싶습니다.
아이디어가 있으십니까?
PHP :
<?php
function backgroundColor(){
$backgroundColor = '';
if (date('H:i') >= strtotime('06:00') && date('H:i') <= strtotime('20:00')){
$backgroundColor == 'blue';
} else {
$backgroundColor == 'black';
}
return $backgroundColor;
}
?>
HTML :
<html>
<head>
<title></title>
<style>
body{
background-color: <?=backgroundColor()?> ;
}
</style>
</head>
<body>
<?php echo date('H:i')?>
</body>
</html>
'$의 backgroundColor = '블루','하지'$의 backgroundColor == '블루', ' –
참조 @MikeW "나는 PHP를 실행하면 ..."는 – Keven
나는이에 훨씬 더 좋은 것 같아요 헤더의 스타일을 직접 변경하지 말고 '
'태그의 클래스를 변경하십시오. – Jeemusu