1

我有一个表格行,其中包含一个 ID,如下所示:

  <td id='errormsg'>$errormsg</td>

在 css 页面中,`#errormsg' id 将文本颜色变为红色,如下所示,在单独的 css 文件中:

#errormsg{
    color:red;  
}

但是我有一点情况。我在这里有一个 if 语句:

if(mail($getemail, $subject, $message, $headers)){
$errormsg = "You have been Registered. You must Activate your Account from the Activation Link sent to <b>$getemail</b>";
                                                }

现在我想要发生的是,如果满足这个 if 语句,我希望 $errormsg 将字体颜色从红色更改为绿色。这真的可能吗?

4

5 回答 5

1

试试这个:

$color = "red";

if(mail($getemail, $subject, $message, $headers)){
    $color = "green";
    $errormsg = "You have been Registered. You must Activate your Account from the Activation Link sent to <b>$getemail</b>";
}
....
echo "<td style='color:$color;' id='errormsg'>$errormsg</td>";
于 2012-08-24T22:50:28.200 回答
1
<?php
$extraErrorClass = '';
if(mail($getemail, $subject, $message, $headers)) {
    $errormsg = "You have been Registered. You must Activate your Account from the Activation Link sent to <b>$getemail</b>";
    $extraErrorClass = ' class="error-green"';
}

echo "<td id='errormsg'$extraErrorClass>$errormsg</td>";
?>

或者也许更好的可读性:

echo '<td id="errormsg"', $extraErrorClass, '>', $errormsg, '</td>';

只需将额外的类添加到您的 CSS 中:

#errormsg.error-green {
    color: green;  
}
于 2012-08-24T22:54:35.527 回答
0
if (mail($getemail, $subject, $message, $headers)) {
  $errormsg = "<span style='color: green'>You have been Registered. You must Activate your Account from the Activation Link sent to <b>$getemail</b></span>";
}
于 2012-08-24T22:50:42.260 回答
0

是的。

PHP:

<?php
// ...
$result = mail($getemail, $subject, $message, $headers);
if($result) {
?>
<div class="message message-success">You have been registered. Please activate your account from the activation link sent to <strong><?php echo $getemail; ?></strong>.
<?php
} else {
?>
<div class="message message-fail">Sorry, an error occurred when sending the activation email to <strong><?php echo $getemail; ?></strong>.
<?php
}
// ...
?>

CSS:

.message {
    text-align: center;
    padding: 20px;
    border: 1px solid #888
}
.message-success {
    background: #afa;
    color: #040
}
.message-fail {
    background: #faa;
    color: #400
}
于 2012-08-24T22:55:22.443 回答
0
#errormsg{
    color:red;  
}

#okmsg{
    color:green;  
}
  $status = "errormsg";
  if(mail($getemail, $subject, $message, $headers)){
    $msg = "You have been Registered. You must Activate your Account from the Activation Link sent to <b>$getemail</b>";
    $status = "okmsg";
  } 
<td id="$status">$msg</td>
于 2012-08-24T22:58:17.850 回答