我需要將 a 的值分配<td>給變量。我<td>通過使用 jQueryclosest()和find()方法找到了。如果我alert這樣做<td>,它會給我正確的價值,但如果我console.log()這樣做,它不會。它返回一個對象。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>放入變量中?我嘗試過使用text(),val()和html()最后thisTaskID但沒有任何效果。預先感謝,你可以猜到我是新來的
1 回答

青春有我
TA貢獻1784條經驗 獲得超8個贊
您可以獲得選擇更改事件的值,因此您不需要其他函數。也許你需要的是這樣的:
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);
});
- 1 回答
- 0 關注
- 143 瀏覽
添加回答
舉報
0/150
提交
取消