尝试创建逗号分隔的字符串

时间:2013-09-05 15:49:32

标签: jquery

我试图关注此example

var tags = $('#MainContent_myTable tr').each(function () {
return $(this).find('.tablecellname').html();
}).get().join(',');
console.log(tags);

当我查看输出时,我得到以下内容:

[object HTMLTableRowElement],[object HTMLTableRowElement],[object HTMLTableRowElement],  
[object HTMLTableRowElement],[object HTMLTableRowElement],[object HTMLTableRowElement], 
[object HTMLTableRowElement],[object HTMLTableRowElement],[object HTMLTableRowElement],
[object HTMLTableRowElement],[object HTMLTableRowElement],[object HTMLTableRowElement],  
[object HTMLTableRowElement],[object HTMLTableRowElement],[object HTMLTableRowElement],
[object HTMLTableRowElement],[object HTMLTableRowElement],[object HTMLTableRowElement], 
[object HTMLTableRowElement],[object HTMLTableRowElement],[object HTMLTableRowElement], 
[object HTMLTableRowElement],[object HTMLTableRowElement],[object HTMLTableRowElement],...

我做错了什么?

1 个答案:

答案 0 :(得分:3)

您使用each()代替map()

var tags = $('#MainContent_myTable tr').map(function () {
    return $(this).find('.tablecellname').html();
}).get().join(',');
console.log(tags);