基本上,我需要帮助使用"td“和"tr”标记在表中显示数据。
html += '<table class="table table-striped">';
for(var i in value){
if(!number_regex.test(i)){
html += '<tr>';
html += '<td>' + i + '</td>';
if(i == 'image_link'){
html += '<td> : ' + '<img src=' + value.image_link + ' alt>' + '</td>';
}
else{
html += '<td> : ' + value[i] + '</td>';
}
html += '</tr>';
}
}
html += '</table><br/>';这是我当前的代码,其中的值是一个对象。这将在每个"tr“中输出一个"td”。我试着在一个"tr“中对齐2”td“。但是,这不能通过next(i)或(i+1)完成,因为它不是一个数字。
到目前为止,我一直在努力做到这一点,但没有结果:
html += '<td>' + next(i) + '</td>';
if(next(i) == 'image_link'){
html += '<td> : ' + '<img src=' + value.image_link + ' alt>' + '</td>';
}
else{
html += '<td> : ' + value[next(i)] + '</td>';
}以及:
html += '<table class="table table-striped">';
html += '<tr>';
for(var i in value){
if(!number_regex.test(i)){
html += '<td>' + i + '</td>';
if(i == 'image_link'){
html += '<td> : ' + '<img src=' + value.image_link + ' alt>' + '</td>';
}
else{
html += '<td> : ' + value[i] + '</td>';
console.log(data);
}
for(var counter = 0; counter <= 8; counter++){
//8 because there are 9 fields in the query I want to display
if(counter % 2 == '0'){
html += '</tr>';
html += '<tr>';
}
}
}伙计们有什么想法吗?这些是你们中的一些人要求的附加信息:我有atm:https://www.dropbox.com/s/kmhkwturtmcxovh/lala.png表的图片,至于html,这是javascript语法,这就是为什么我以这种方式使用html的原因。
发布于 2014-01-13 08:09:22
接受一个变量并将其放入循环中,循环通过添加</tr>...something来完成结束行的工作,如下所示:
这就是你现在拥有的:
html += '</tr>';修改如下:
$var = 0; /* initiaize it somewhere outside for(var i in value) */
if(++$var < 2)
{
/* do not echo </tr> if 2 td's haven't been added */
}
else /* 2 td's have been added, end this row */
{
$var = 0; /* reset counter*/
html += '</tr>'; /* end rows */
}https://stackoverflow.com/questions/21085721
复制相似问题