能够通过点击按钮来改变独立的div的颜色 [英] Be able to change the colour of seperate divs by clicking on buttons

查看:164
本文介绍了能够通过点击按钮来改变独立的div的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建婚礼清单网站。
对于我的清单,我想让用户将todo项目的颜色更改为红色,琥珀色和绿色,红色为未完成,琥珀色为部分完成,绿色为完成。我是wndering如何实现这一点,我也希望它被保存到数据库。
提前感谢。

    解决方案


  1. 添加一列值为1或2的数字 status (它将是状态的ID)

  2. 使用 status_id status_title status c>, status_color color_id 启用


  1. 您的div,通过获取存储的id获取任务的颜色



    $ colorOfTheTask =SELECT color_id FROM status,task WHERE task.status = (我假设你在使用表格)
    <$ c(

    $ c>< td<?php echo'style =background-color:'。$ color_id。'; color:'。$ color_id。'';?>< / td>

像这样,您就可以更轻松地管理颜色。您仍然可以使用如下的if语句:

 < td<?php 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:#amber-color-code; color:#amber-color-code >
< / td>


I am creating a wedding checklist website. For my checklist I want to enable the user to change the colour of the todo item to red, amber and green, red for not done, amber for partly done, and green for done. I was wndering how to achieve this, I would also like it to be saved to the database. Thanks in advance.

解决方案

in db

  1. add a column status with a value of 1 or 2 numbers ( it'll be the id of a status)
  2. Create a table status with a status_id, status_title ,status_color, color_id, enabled

in your code :

  1. in your div , get the color of the task by getting the stored id

    $colorOfTheTask = "SELECT color_id FROM status,task WHERE task.status = status.id ";

  2. Use this on each of your td (i suppose you're using tables) <td <?php echo 'style="background-color:'.$color_id.';color:'.$color_id.'"';?></td>

Like that you'll be able to manage your colours easier. You can still use a if statement like this :

<td <?php 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:#amber-color-code;color:#amber-color-code"';} ?>
</td>

这篇关于能够通过点击按钮来改变独立的div的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆