1

我有以下代码来加载基于值的输入字段的颜色gap

echo "<td class='gap'>";
echo "<input name = gap-".$compi['Competence_ID']." type='text' readonly style='width:20px;' value='";
if(isset($compi['gap']) && $compi['gap']!=0){
    echo $compi['gap'];
}
$color='';
if($compi['gap']>=0){
    $color='#3CB371';$text="gap bigger than 0";
}
if($compi['gap']<0){
    $color='#FFFFFF';$text="gap is not";
}
echo "' style='background-color:".$color.";'>";
echo $text."</td>";

代码打印正确,$text但输入的颜色没有改变..

4

3 回答 3

1

尝试:

echo '<td class="gap">';
echo '<input name = "gap-'.$compi['Competence_ID'].'" type="text" readonly value="';
if(isset($compi['gap']) && $compi['gap']!=0){
    echo $compi['gap'];
}
$color='';
if($compi['gap']>=0){
    $color='#3CB371';$text="gap bigger than 0";
}
if($compi['gap']<0){
    $color='#FFFFFF';$text="gap is not";
}
echo '" style="width:20px;background-color:'.$color.';">';
echo $text."</td>";

请记住,HTML 属性应该在双引号之间,并且这些引号不应该是错误的。属性上有一个错误引用name。并且不能有重复的属性。

于 2013-04-18T15:34:40.473 回答
1

这是因为您的标签有两个style属性<input>- 在一个属性中添加两个 CSS 规则,您应该没问题。

于 2013-04-18T15:32:13.830 回答
0

The CSS proberty "color" is for the text color, "background-color" is what you're searching for :)

http://www.w3schools.com/cssref/pr_background-color.asp

于 2013-04-18T15:29:26.507 回答