繁体   English   中英

更改整行的颜色

[英]change the color on the full line

我这样写表格:

tbody.append(
 $(`<tr class="table__row" id="${ Ida }, ${ Paraa }" style="font-weight: ${ Stat != '0' ? 'bold' : 'normal' }; font-size: 90%">`).on("click", "td", marld)
    .append($(`<td class="table__content" data-heading="De">`).append(data[i][1]))
    .append($(`<td class="table__content" data-heading="Tipo">`).append(data[i][8]))
    .append($(`<td class="apagar table__content" data-heading="Assunto" data-alerta="${ Ida }, ${ Paraa }">`).append(data[i][2]))
    .append($(`<td class="table__content" data-heading="Conteúdo">`).append(data[i][3]))
    .append($(`<td class="table__content" data-heading="Estado">`).append(data[i][4]))
    .append($(`<td class="table__content" data-heading="Recebido">`).append(data[i][5]))
)

然后我使用这个 function 将它插入到表中,如果我返回一个,将行的颜色从粗体更改为正常:

function marld(){
    var ite_id = []; 
    ite_id1 = $(this).parents("tr").attr("id");
    
    $(".colorir").each(function(){ //percorre todos os tr que possui a classe colorir
        ite_id.push(ite_id1); //adiciona o id da linha ao array
    })

    $.ajax({
        url: './marcaler',
        type: 'POST',
        cache: false,
        data: {ite_id:ite_id},
        error: function(){

        },
        success: (result) => // *** Arrow function
        { 
            if(result != ''){
                $(this).css("font-weight", "normal") // *** Use `this`
            }
        }
    });      
}  

它正在工作,但有一个我想改进的问题。

实际上,只有我单击的列发生了变化。

我想单击其中一列以将整行更改为正常。

您需要更改行的font-weight样式,而不是单元格,而是应用于单元格的marld (因为on("click", "td", marld) )。

所以这里的this等于我们点击的单元格:

$(this).css("font-weight", "normal")

例如,您可以使用parent()将 go 提高 1 级:

$(this).parent().css("font-weight", "normal")

因为<td>的父级是<tr>

尝试改变

$(this).css("font-weight", "normal")

$(this).parent().css("font-weight", "normal")

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM