JQuery函数返回一个对象,但它被集成为未定义

时间:2013-08-03 11:58:43

标签: javascript jquery

我试图通过按钮点击功能从对象中获取对象。

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

1 个答案:

答案 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;
}