我是新手。我正在创建一个网站,用户可以在其中将信息输入到待办事项列表中。我有一个用于待办事项列表的插件,它是用 javascript 完成的并连接到我的数据库,但我希望用户能够更改待办事项的状态,所以会有一个按钮说完成,部分完成,和尚未完成。当他们点击这个待办事项时,它会改变颜色以表示已完成、未完成或部分完成。我在数据库中的 todo 表中输入了一个 status
行,但我不确定如何实现这一点的代码。
在我数据库中的 todolist 表中,有 id
、content
和现在的 status
。
提前致谢
todo.addList = function (text){
$.ajax({
url: 'server.php',
method: 'GET',
data: 'op=addList&content='+text,
dataType: "json", // response as json
error: function(res){
todo.updateInfo("Failed to add new entry");
},
success: function(res){
todo.updateInfo("New Entry added");
todo.addView(res);
}
});
这是从服务器“获取”信息的代码
最佳答案
并将状态存储在数据库中:
1- 添加一列 status_id
,其值为 1 或 2 个数字(它将是状态的 id)
I have inputed a status row into my todo table in the database
所以在这个待办事项表中添加你的列
2- 使用 status_id, status_title ,status_color, color_id, enabled
创建表状态
看看这个: Be able to change the colour of seperate divs by clicking on buttons
//编辑清楚: 最后你会得到类似的东西:
// mysql query wich get all todo
$res=mysql_query("SELECT todo_name,todo_status FROM todo,status WHERE todo.status = status.id
// loop wich write all todo in the html table
while($tab=mysql_fetch_array($res))
{
echo "<tr> <td>".$name."<td";
if($id_status==1){
echo 'style="background-color:red;color:red';}
if($id_status==2){
echo 'style="background-color:green;color:green';}
if($id_status==3){
echo 'style="background-color:#something;color:#something"';}
echo "</td>";
}
关于javascript - 根据php中的状态更改元素的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22200628/