更新1分钟后更改行的颜色

时间:2016-06-17 13:43:46

标签: javascript php jquery css codeigniter

我使用codeigniter,CSS和JQuery。我想在1分钟后改变一行的背景颜色。在更新操作1分钟后,该行将像其他行一样获得默认颜色。

任何想法,任何功能,任何人都可以帮助!

感谢您的帮助。

2 个答案:

答案 0 :(得分:1)

当你刚刚更新了行

时,

启动setTimeout功能

// maybe you could give the row a class such as .updated
var row = $('table tr.updated');
updateRow(row);

// or maybe the updated row is always the last one?
var row = $('table tr').last();
updateRow(row);

function updateRow(row)
{
    // do all the stuff associated with updating the row

    // note that you're going to actually have to find row yourself or
    // pass it in as an element

    $(row).css('background-color', 'red');

    setTimeout(function() {
        $(row).css('background-color', your default color);
    }, 60000);
}

答案 1 :(得分:0)

您必须使用setTimeout(function, miliseconds) 例如:

function setColorTemporary(obj) {
    $(obj).css("background-color", "blue");
    setTimeout(function() 
    {
        $(obj).css("background-color", "transparent");
    }, 60000); //60 seconds
}

setColorTemporary($("#id987")); //Set color for any object for 1 minute

在控制器中,也许......

<?php
class MyController extends CI_Controller {

    public function method()
    {
            $id = "#id987";
            echo "<script>setColorTemporary($('$id'));</script>";
    }
}