簡體   English   中英

在表格中選擇填充的單元格

[英]Select Filled Cell in Table

如果單元格已滿,我試圖使其可編輯。 如果尚未填寫,將無法編輯。

我正在使用contenteditable,但我無法選擇所有符合我條件的td。 當我嘗試寫時,如果填充了一個td,則選擇所有td。 我嘗試在foreach內編寫代碼,但是我想我不能這樣做,因為jquery選擇不會返回任何數組等。

你有什么建議嗎?

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');
});

編輯:解決方案建議

也許我應該嘗試為可填充的行提供可編輯的類,然后使用此類名稱進行選擇?

嘗試檢查元素內部文本而不是元素本身,如下所示:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM