如何使用 javascript 或打字稿在表中获取 tr 的第二个 td 值



我试图在表中获取tr的第二个td值,但没有摇摆不定。我妈找到不是一个函数。那么如何使用javascript或打字稿在表中获取tr的第二个td值。不要使用 jquery。

let target = e.originalEvent.toElement.closest('tr');
if (target && target.id) {
let td = target.find('td:nth-child(2)');
let fieldValue = e.data[target.id];
if (td) {
console.log("This row ID is ="+ td.value )
} 
} 

.find查找与选择器匹配的后代是一个jQuery方法,但你没有使用jQuery(你不想使用,这很好(。请改用querySelector,它支持 jQuery 所做的大多数选择器:

const target = e.originalEvent.toElement.closest('tr');
if (target && target.id) {
const td = target.querySelector('td:nth-child(2)');
const fieldValue = e.data[target.id];
if (td) {
console.log("This row ID is =" + td.value)
}
}

最新更新