[英]Get value from td after .closest() .find() .html()
I need to assign the value from a <td>
to a variable.我需要将
<td>
中的值分配给变量。 I find the <td>
by using the jQuery closest()
and find()
methods.我通过使用 jQuery
closest()
和find()
方法找到了<td>
。
If I alert
the <td>
it gives me the correct value but if I console.log()
it it doesn't.如果我
alert
<td>
它会给我正确的值,但如果我console.log()
它不会。 It returns an object.它返回一个 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);
}
How do I get the value of the found <td>
into a variable?如何将找到的
<td>
的值放入变量中?
I've tried using text()
, val()
and html()
at the end of thisTaskID
but nothing works.我尝试在
thisTaskID
的末尾使用text()
、 val()
和html()
,但没有任何效果。
Thanks in advance, as you can guess I'm new提前谢谢,你可以猜到我是新来的
You get the value on selection change event, therefor you need no other function for it.您获得选择更改事件的值,因此您不需要其他 function 。 Probably anything you need is this:
可能您需要的任何东西都是这样的:
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.