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

JQuery function returning an object but its being integrated as undefined

本文关键字:集成 未定义 对象 函数 返回 一个对象 JQuery      更新时间:2023-09-26

我正试图在单击按钮时从函数中获取一个对象。

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

i跳出循环,在底部添加了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;
}