我遇到了一个小问题。我的代码到目前为止自动生成该月的所有日期到单独的框中。就像日历格式一样。
$number = cal_days_in_month(CAL_GREGORIAN, 7, 2016);
// LOOP THROUGH THE NUMBER OF MONTHS USING FOR-LOOP AND CREATE
// THE BOXES THAT YOU DESIRE (WITH CSS-CLASSES, THOUGH)
$calBoxes = "";
//makes numbers 1 after the other
for($cue=1; $cue<=$number; $cue++){
//adds the date
$fmtDay = date("D", strtotime("2016-7-{$cue}"));
//adds div for outside box
$calBoxes .= "<div id='box' class='date-box date-box-{$cue}'>" . PHP_EOL;
$calBoxes .= "<span class='date-number date-number-{$cue}'>{$fmtDay}</span>" . PHP_EOL;
$calBoxes .= "<span class='weekday weekday-{$cue} weekday-" . strtolower($fmtDay) . "'>{$cue}</span>" . PHP_EOL;
$calBoxes .= "</div>" . PHP_EOL;
}
我遇到的问题是我找不到根据变量中的数字使某个盒子成为某种颜色的方法。说数字为7它将使第7个盒子的结果是星期四7某种颜色。将其余部分保留为默认值。
这是方框的css
#box{
background-color:black;
width: 75px; height: 75px;
border: solid 1px white; display: inline-block;
font-size:20px;
}
对于在特定版本中声明的框号,它需要更改为绿色而不是黑色。
答案 0 :(得分:0)
这就是我用它来转换绿色变量中指定的数字。
$number = cal_days_in_month(CAL_GREGORIAN, 7, 2016);
// LOOP THROUGH THE NUMBER OF MONTHS USING FOR-LOOP AND CREATE
// THE BOXES THAT YOU DESIRE (WITH CSS-CLASSES, THOUGH)
$calBoxes = "";
//makes numbers 1 after the other
for($cue=1; $cue<=$number; $cue++){
//adds the date
$fmtDay = date("D", strtotime("2016-7-{$cue}"));
$var ="2";
if ($var == $cue) $color = 'green';
else {$color ='black';}
$calBoxes .= "<div style= class='date-box date-box-{$cue}'>" . PHP_EOL;
$calBoxes .= "<span style=\"color: $color;\" class='date-number date-number-{$cue}'>{$fmtDay}</span>" . PHP_EOL;
$calBoxes .= "<span class='weekday weekday-{$cue} weekday-" . strtolower($fmtDay) . "'>{$cue}</span>" . PHP_EOL;
$calBoxes .= "</div>" . PHP_EOL;
}
?>
<div id=margindate>
请随时修改问题,使其更易于理解。