如何使用追加javascript

时间:2016-05-26 22:30:57

标签: javascript html macros confluence

我想计算表格中每一列末尾的已检查任务的数量,并将其显示在最后一行但是显示为绿色,然后执行相同操作以取消选中,并将其显示为红色。

<script type="text/javascript">
(function ($) {
AJS.toInit(function() {
    var tables = $('table').has('.inline-task-list');
    tables.each(function() {
        var table = $(this);

        //calculates rows checked count
        if (table.find('tr').has('.inline-task-list').eq(0).find('.inline-task-list').length > 1) {
            table.find('tr').has('.inline-task-list').each(function() {
                var row = $(this);
                var tasks = row.find('li[data-inline-task-id]');
                var checkedCount = tasks.filter('.checked').length;
                var uncheckedCount = tasks.length - checkedCount;
                row.find('td').last().append(checkedCount + ' Company Task Completed ' + ' <br> ');
                row.find('td').last().append(uncheckedCount + '<strong> Company Task Remaining </storng>');
            });
        }

        //calculates columns checked count
        table.find('tr:eq(0) th').each(function(i) {
            var tasks = table.find('tr').find('td:eq(' + i + ') li[data-inline-task-id]');
            if (tasks.length > 1) {
                var checkedCount = tasks.filter('.checked').length;
                var uncheckedCount = tasks.length - checkedCount;
                    table.find('tr').last().find('td').eq(i).append(checkedCount + ' Company Task Completed ' + '<br>');
                    table.find('tr').last().find('td').eq(i).append(uncheckedCount + '<strong> Company Task Remaining </storng>');                  
            }
        });
    });
});
})(AJS.$);

我确实尝试通过执行以下操作来更改颜色,但我意识到我只是将其全部更改为绿色然后是红色。我无法隔离文本字符串以单独更改它们。

var uncheckedCount = tasks.length - checkedCount;
                    table.find('tr').last().find('td').eq(i).append(checkedCount + ' Company Task Completed ' + '<br>');
                    table.find('tr').last().find('td').eq(i).css('color','green');
                    table.find('tr').last().find('td').eq(i).append(uncheckedCount + '<strong> Company Task Remaining </storng>');
                    table.find('tr').last().find('td').eq(i).css('color','red');    

0 个答案:

没有答案