[英]Select Filled Cell in Table
I am trying to make editable if the cell is filled. 如果单元格已满,我试图使其可编辑。 If it is not filled yet, it will not be editable.
如果尚未填写,将无法编辑。
I am using contenteditable but I can not select the td's all is fit my condition. 我正在使用contenteditable,但我无法选择所有符合我条件的td。 When I try to write if, when one td is filled all td's are chosen.
当我尝试写时,如果填充了一个td,则选择所有td。 I tried to write if inside of foreach but I guess I can not do this because jquery selection doesnt return any array etc.
我尝试在foreach内编写代码,但是我想我不能这样做,因为jquery选择不会返回任何数组等。
Do you have any suggestion ? 你有什么建议吗?
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');
}
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');
});
edit: Solution Suggestion 编辑:解决方案建议
Maybe I should try to give editable class for the filled rows and then selected with this class name ? 也许我应该尝试为可填充的行提供可编辑的类,然后使用此类名称进行选择?
Try to check the element inner text NOT the element itself as in: 尝试检查元素内部文本而不是元素本身,如下所示:
if(edit3.text().trim() != "" && edit4.text().trim() != ""){ edit3.attr('contenteditable','true'); edit4.attr('contenteditable','true'); }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.