for循环里面的append不起作用 [英] for loop inside the append is not working
本文介绍了for循环里面的append不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
$(< table />,{cellspacing:0 ,cellpadding:0,border:0,width:100%})
.append(
$(< tbody />)
.append(function(){
options = [ONE,TWO,THREE,FOUR];
$ .each(options,function (val){
return($(< tr />)
.append(
$(< td />)。html / 2013年10月14日),
$(< td />)。html(5/6/2013 10:42),
$(< td /> (< img src ='pdf_16x16.png'/>),
$(< td />)。 < td />)。html(< a href ='#'>重新上传文件< / a>)
));
})
})
).appendTo(body);
for循环在append中不起作用。
追加函数返回任何东西,只有
每个
循环内。试试看: $(< tbody />)。append(function(){
options = [ONE,TWO,THREE,FOUR];
var $ container = $('< table>< / table>);
$ .each(options,function(val){
$ container.append($(< tr />)。append(
$(< td />) (2013/6/2013 10:41),
$(< td />)。html(5/6/2013 10:42),
$( (< td />)。html(val),
$(< td />
$(< td />)。html(< a href ='#'>重新上传文件< / a>)
));
});
return $ container.html();
});
below is my code.
$("<table/>",{"cellspacing":"0","cellpadding":"0","border":"0","width":"100%"})
.append(
$("<tbody/>")
.append(function(){
options=["ONE","TWO","THREE","FOUR"];
$.each(options, function(val) {
return ($("<tr/>")
.append(
$("<td/>").html("4/6/2013 10:41"),
$("<td/>").html("5/6/2013 10:42"),
$("<td/>").html(val),
$("<td/>").html("<img src='pdf_16x16.png'/>"),
$("<td/>").html("<a href='#'>Re-Upload Documents</a>")
));
})
})
).appendTo("body");
for loop inside the append is not working.
解决方案
The problem is because you are not returning anything from the append
function, only the each
loop within it. Try this:
$("<tbody/>").append(function(){
options = ["ONE","TWO","THREE","FOUR"];
var $container = $('<table></table>');
$.each(options, function(val) {
$container.append($("<tr/>").append(
$("<td/>").html("4/6/2013 10:41"),
$("<td/>").html("5/6/2013 10:42"),
$("<td/>").html(val),
$("<td/>").html("<img src='pdf_16x16.png'/>"),
$("<td/>").html("<a href='#'>Re-Upload Documents</a>")
));
});
return $container.html();
});
这篇关于for循环里面的append不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文