Javascript 选择表格中的填充单元格

Javascript 选择表格中的填充单元格,javascript,jquery,selection,contenteditable,Javascript,Jquery,Selection,Contenteditable,如果单元格已填充,我将尝试使其可编辑。如果尚未填写,则不可编辑 我使用的是contenteditable,但我无法选择td的all is fit my condition。当我尝试写if时,当一个td被填充时,所有td都被选中。我试图在foreach内部编写if,但我想我不能这样做,因为jqueryselection不返回任何数组等 你有什么建议吗 var edit3 = $('#table_mresults tbody tr').find(':nth-child(3)'); var edit4

如果单元格已填充,我将尝试使其可编辑。如果尚未填写,则不可编辑

我使用的是contenteditable,但我无法选择td的all is fit my condition。当我尝试写if时,当一个td被填充时,所有td都被选中。我试图在foreach内部编写if,但我想我不能这样做,因为jqueryselection不返回任何数组等

你有什么建议吗

var edit3 = $('#table_mresults tbody tr').find(':nth-child(3)');
var edit4 = $('#table_mresults tbody tr').find(':nth-child(4)');

if(edit3 != "" && edit4 != ""){


    edit3.attr('contenteditable','true');
    edit4.attr('contenteditable','true');
}

编辑:解决方案建议


也许我应该尝试为填充行指定可编辑类,然后使用此类名选择?

尝试检查元素内部文本,而不是元素本身,如中所示:

if(edit3.text().trim()!=“”&edit4.text().trim()!=“”){
edit3.attr('contenteditable','true');
edit4.attr('contenteditable','true');

}
否,检查元素本身没有任何问题。我可以编辑它们!问题是,当其中任何一行被填充时,当我写入edit3.attr('contenteditable','true')时,所有行的第三个tds也被选中
var edit3 = $('#table tbody tr').find(':nth-child(3)');
var edit4 = $('#table tbody tr').find(':nth-child(4)');

edit3.forEach(e3 => {
    if(e3 != "") e3.attr('contenteditable','true');
});

edit4.forEach(e4 => {
    if(e4 != "") e4.attr('contenteditable','true');
});