我试图通过按钮点击功能从对象中获取对象。
该函数返回一个对象(使用Google工具检查),但返回值“tr”未定义。
按钮
$("#btnView").on("click", function () {
var tr = GetActiveRow(); <-- the tr value is coming as undefined
var itemNumber = tr.find("td").eq(0).html();
});
功能
function GetActiveRow() {
var rows = $(".datagrid tr:gt(0)");
rows.each(function (index) {
//If its currently active override it so we can mark new row
var rowdata = $(this).data;
if ($(this).data("isActive") == true) {
alert($(this));
return $(this).get(); <-----object is being turned because the alert message is displayed
}
});
}
答案 0 :(得分:0)
我跳出了循环添加的返回语句在底部并且它起作用了:D
function GetActiveInvoiceRow() {
var trRow = null;
var rows = $(".datagrid tr:gt(0)");
rows.each(function (index) {
//If its currently active override it so we can mark new row
var rowdata = $(this).data;
if ($(this).data("isActive") == true) {
trRow = $(this);
return;
}
});
return trRow;
}