fornd中的for循环不起作用
下面是我的代码。
$("
",{"cellspacing":"0","cellpadding":"0","border":"0","width":"100%"}) .append( $("") .append(function(){ options=["ONE","TWO","THREE","FOUR"]; $.each(options, function(val) { return ($(" ") .append( $(" ").html("4/6/2013 10:41"), $(" ").html("5/6/2013 10:42"), $(" ").html(val), $(" ").html(""), $(" ").html("Re-Upload Documents") )); }) }) ).appendTo("body");
fornd中的for循环不起作用。
问题是因为你没有从append
函数返回任何东西,只返回其中的each
循环。 试试这个:
$("").append(function(){ options = ["ONE","TWO","THREE","FOUR"]; var $container = $('
'); $.each(options, function(val) { $container.append($(" ").append( $(" ").html("4/6/2013 10:41"), $(" ").html("5/6/2013 10:42"), $(" ").html(val), $(" ").html(""), $(" ").html("Re-Upload Documents") )); }); return $container.html(); });
示例小提琴
尝试
var tbody = $("").appendTo($("
", { "cellspacing" : "0", "cellpadding" : "0", "border" : "0", "width" : "100%" }).appendTo("body")); options = ["ONE", "TWO", "THREE", "FOUR"]; $.each(options, function(key, val) { return tbody .append($(" ") .append($(" ").html("4/6/2013 10:41")) .append($(" ").html("5/6/2013 10:42")) .append($(" ").html(val)) .append($(" ").html("")) .append($(" ").html("Re-Upload Documents"))); })
演示: 小提琴
试试吧
$.each(options, function(val) { return ($(" ") .append( $(" ").html("4/6/2013 10:41") + $(" ").html("5/6/2013 10:42") + $(" ").html(val) + $(" ").html("") + $(" ").html("Re-Upload Documents") )); })
尝试以下:
$("
",{"cellspacing":"0","cellpadding":"0","border":"0","width":"100%"}) .append("").appendTo("body"); $("tbody").append(function(){ options = ["ONE","TWO","THREE","FOUR"]; var $container = $(''); $.each(options, function(val) { $container.append($(" ").append( $(" ").html("4/6/2013 10:41"), $(" ").html("5/6/2013 10:42"), $(" ").html(val), $(" ").html(""), $(" ").html("Re-Upload Documents") )); }); return $container.html(); });
在这里工作小提琴: http : //jsfiddle.net/mCLsm/2/