admin管理员组文章数量:1332324
My problem is that the html variable returns something like this: [object Object][object Object][object Object][object Object][object Object], instead of the elements.
What should i do different?
var html = '';
$.each(data.response, function(index, value) {
var tr = $('<tr>');
var tr_data = '<td>asd</td>';
html += tr.data('trackinfo',value).html(tr_data);
});
$(target).html(html);
My problem is that the html variable returns something like this: [object Object][object Object][object Object][object Object][object Object], instead of the elements.
What should i do different?
var html = '';
$.each(data.response, function(index, value) {
var tr = $('<tr>');
var tr_data = '<td>asd</td>';
html += tr.data('trackinfo',value).html(tr_data);
});
$(target).html(html);
Share
Improve this question
edited Dec 22, 2015 at 20:08
Brian Tompsett - 汤莱恩
5,89372 gold badges61 silver badges133 bronze badges
asked Feb 13, 2012 at 16:11
passatgtpassatgt
4,4425 gold badges43 silver badges56 bronze badges
1
-
Can you please post what the
data
variable contains. I'm guessing JSON? – Rory McCrossan Commented Feb 13, 2012 at 16:13
2 Answers
Reset to default 4That's because you're setting the data on the tr
and then filling it with your html, but still concatinating an object, which converts it to a string... aka
"[object Object]"
Not exactly sure what you're after but you might try changing this...
html += tr.data('trackinfo',value).html(tr_data);
To this...
html += tr.data('trackinfo',value).html(tr_data).html();
By default, Jquery creates objects not html mark-up. To get html you should to call html() method.
Here is working code:
var html = '';
$.each(data.response, function(index, value) {
var tr = $('<tr>');
var tr_data = '<td>asd</td>';
html += tr.data('trackinfo',value).html(tr_data);
});
$(target).html(html);
本文标签: javascriptjQuery each returns object ObjectStack Overflow
版权声明:本文标题:javascript - jQuery each returns [object Object] - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742267432a2443673.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论