2013-08-03 68 views
0

我想从按钮单击功能获取对象。JQuery函数返回一个对象,但它被集成为undefined

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

会之一为tr一次活跃? – krishgopinath

回答

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