0

我正在尝试通过单击按钮从函数中获取对象。

该函数正在返回一个对象(使用 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 
    }
});
}
4

1 回答 1

0

我跳出循环,在底部添加了 return 语句,它起作用了: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;
}
于 2013-08-03T12:02:30.533 回答