[英]Get value from td after .closest() .find() .html()
我需要將<td>
中的值分配給變量。 我通過使用 jQuery closest()
和find()
方法找到了<td>
。
如果我alert
<td>
它會給我正確的值,但如果我console.log()
它不會。 它返回一個 object。
function getval(sel) {
var thisTaskID = $(".selTaskOwner").on("change", function() {
var currentRow = $(this).closest("tr");
var foundTaskID = currentRow.find("td:eq(0)").html();
alert(foundTaskID);
});
console.log(thisTaskID);
}
如何將找到的<td>
的值放入變量中?
我嘗試在thisTaskID
的末尾使用text()
、 val()
和html()
,但沒有任何效果。
提前謝謝,你可以猜到我是新來的
您獲得選擇更改事件的值,因此您不需要其他 function 。 可能您需要的任何東西都是這樣的:
var foundTaskID = 0;
$(".selTaskOwner").on("change", function() {
foundTaskID = $(this).closest("tr").find("td:eq(0)").html();
/* Do what you want with it... */
console.log(thisTaskID);
alert(foundTaskID);
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.