我在表格中添加了“状态”列,并输入了数字,以便与 ID 和内容一起显示。
$res_array = array();
// fetch all the entires one by one
while($row=mysql_fetch_array($res)){
// put query result in php array
$array = array('id' => $row['id'],
'content' => $row['content'],
'status'=> $row['status']);
// add into the big array
$res_array[] = $array;
// update the list view
for (var i=0; i< res.length; i++){
$("<li/>", {"id": res[i].id, "text": res[i].content + res[i].status}).appendTo(todo.list);
// Extend the width if msg is too long
if(res[i].content.length >= 35){
$('#'+res[i].id).css("height","50px");
}
}
在上面你可以看到它是如何显示的,我仍然无法得到 if 语句来更改内容的颜色。
我希望内容根据状态号改变颜色。 我不知道代码,但我想象这将是状态的 if 语句,但我需要帮助 提前致谢。
最佳答案
如果您有有限且已定义的状态代码列表,那么我建议只需将它们添加到 CSS 类(例如 status5),然后为您返回的每个状态代码定义颜色/样式作为基本 CSS 规则
.status5 { color: red }
关于javascript - 以数字形式输出状态,改变颜色的代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22202998/