[英]How to get second td value of tr in a table using javascript or typescript
我試圖在表中獲取 tr 的第二個 td 值,但沒有得到 wokring。我發現 find 不是一個函數。所以如何使用 javascript 或 typescript 在表中獲取 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)
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.