代码之家  ›  专栏  ›  技术社区  ›  Parker

如何使表格行的单元格项加粗n秒?

  •  0
  • Parker  · 技术社区  · 3 年前

    我有一段代码,我调用我的服务器获取一些值,如果该值不存在,则更新表。更新之后,我希望通过将单元格值设为粗体n秒来通知用户更新值的行。

    var table=document.getElementById("employee_details");
    
    var jsonString = JSON.stringify(array);
    
    $.ajax({
        url: '/server.php',
        type: 'POST',
        data: {"input":"calculate_charges",
               data:jsonString},
        cache: false,
        success:function(response){
    
            const arr3=JSON.parse(response);
    
            for(var i=0; i<arr3.length; i++){
    
                if(table.rows[i+1].cells.item(10).innerHTML!=arr3[i][2]){
    
                     table.rows[i+1].scrollIntoView({
                         behavior: 'smooth',
                         block: 'center'
                     });
    
                     table.rows[i+1].cells.item(10).innerHTML=arr3[i][2];
    
                     setTimeout(function(){
                           table.rows[i+1].cells.item(10).style.fontWeight = "500";
                     },7000);
    
                     setTimeout(function(){
                           table.rows[i+1].cells.item(10).style.fontWeight = "900";
                     },4000);
                }
            }
        }
        complete:function(){}
    });
    

    在执行代码时,我在控制台中不断遇到以下错误:

    未捕获类型错误:无法读取未定义(正在读取)的属性 “细胞”)

    而且单元格项不加粗。如何解决此问题?

    1 回复  |  直到 3 年前
        1
  •  1
  •   Oleg    3 年前

    使用let-in for循环:

    for(let i=0; i<arr3.length; i++){
    

    关于let: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let