Javascript jQuery:html表上的多行操作

Javascript jQuery:html表上的多行操作,javascript,jquery,html-table,cell,lines,Javascript,Jquery,Html Table,Cell,Lines,我有这样一个html表: time | time_diff 12:01| 12:21| 12:31| 如何使用Javascript(带或不带jQuery)计算时间差,使我的表看起来像: time | time_diff 12:01| 20 12:21| 10 12:31| 我基本上想知道如何在html表上实现多行操作?类似的东西… function set(i, val) { sets value of seconds column, row i } function get(i) {r

我有这样一个html表:

time | time_diff
12:01| 
12:21|
12:31|
如何使用Javascript(带或不带jQuery)计算时间差,使我的表看起来像:

time | time_diff
12:01| 20
12:21| 10
12:31| 

我基本上想知道如何在html表上实现多行操作?

类似的东西…

function set(i, val) { sets value of seconds column, row i }
function get(i) {returns time from first column, row i;}
function diff(time1, time2) { returns difference }

last = '';
for(i=0,i<rows;i++){
 if(i>0) set(i-1, diff(get(i), last));
 last = get(i);
}

像这样的…

function set(i, val) { sets value of seconds column, row i }
function get(i) {returns time from first column, row i;}
function diff(time1, time2) { returns difference }

last = '';
for(i=0,i<rows;i++){
 if(i>0) set(i-1, diff(get(i), last));
 last = get(i);
}

像这样的…

function set(i, val) { sets value of seconds column, row i }
function get(i) {returns time from first column, row i;}
function diff(time1, time2) { returns difference }

last = '';
for(i=0,i<rows;i++){
 if(i>0) set(i-1, diff(get(i), last));
 last = get(i);
}

像这样的…

function set(i, val) { sets value of seconds column, row i }
function get(i) {returns time from first column, row i;}
function diff(time1, time2) { returns difference }

last = '';
for(i=0,i<rows;i++){
 if(i>0) set(i-1, diff(get(i), last));
 last = get(i);
}

也许是这样的:

$('table tbody tr').each(function () {

    var $row = $(this),
        $nextRow = $row.next();

    if ($nextRow.length) {
        this.cells[1].innerHTML = timeDiff($nextRow.find('td').text(), $row.find('td').text());
    }
});

function timeDiff(t1, t2) {
    t1 = t1.split(':');
    t2 = t2.split(':');
    var diff = (t1[0] * 60 + +t1[1]) - (t2[0] * 60 + +t2[1]),
        hours = Math.floor(diff / 60),
        minutes = (diff - hours * 60) + '';
    return hours + ':' + (minutes.length == 1 ? '0' + minutes : minutes);
}

演示:可能是这样的:

$('table tbody tr').each(function () {

    var $row = $(this),
        $nextRow = $row.next();

    if ($nextRow.length) {
        this.cells[1].innerHTML = timeDiff($nextRow.find('td').text(), $row.find('td').text());
    }
});

function timeDiff(t1, t2) {
    t1 = t1.split(':');
    t2 = t2.split(':');
    var diff = (t1[0] * 60 + +t1[1]) - (t2[0] * 60 + +t2[1]),
        hours = Math.floor(diff / 60),
        minutes = (diff - hours * 60) + '';
    return hours + ':' + (minutes.length == 1 ? '0' + minutes : minutes);
}

演示:可能是这样的:

$('table tbody tr').each(function () {

    var $row = $(this),
        $nextRow = $row.next();

    if ($nextRow.length) {
        this.cells[1].innerHTML = timeDiff($nextRow.find('td').text(), $row.find('td').text());
    }
});

function timeDiff(t1, t2) {
    t1 = t1.split(':');
    t2 = t2.split(':');
    var diff = (t1[0] * 60 + +t1[1]) - (t2[0] * 60 + +t2[1]),
        hours = Math.floor(diff / 60),
        minutes = (diff - hours * 60) + '';
    return hours + ':' + (minutes.length == 1 ? '0' + minutes : minutes);
}

演示:可能是这样的:

$('table tbody tr').each(function () {

    var $row = $(this),
        $nextRow = $row.next();

    if ($nextRow.length) {
        this.cells[1].innerHTML = timeDiff($nextRow.find('td').text(), $row.find('td').text());
    }
});

function timeDiff(t1, t2) {
    t1 = t1.split(':');
    t2 = t2.split(':');
    var diff = (t1[0] * 60 + +t1[1]) - (t2[0] * 60 + +t2[1]),
        hours = Math.floor(diff / 60),
        minutes = (diff - hours * 60) + '';
    return hours + ':' + (minutes.length == 1 ? '0' + minutes : minutes);
}

演示:到目前为止你做了什么?你正在从数据库中提取数据吗?如果是这样,您可以在sql语句中执行此操作。不,我无法编辑sql查询。我正在编写客户端脚本。到目前为止,您做了什么?您正在从数据库中提取数据吗?如果是这样,您可以在sql语句中执行此操作。不,我无法编辑sql查询。我正在编写客户端脚本。到目前为止,您做了什么?您正在从数据库中提取数据吗?如果是这样,您可以在sql语句中执行此操作。不,我无法编辑sql查询。我正在编写客户端脚本。到目前为止,您做了什么?您正在从数据库中提取数据吗?如果是这样,您可以在sql语句中执行此操作。不,我无法编辑sql查询。我正在编写客户端脚本。