如何在不使用div的情况下使用javascript填充html表?

如何在不使用div的情况下使用javascript填充html表?,javascript,jquery,html-table,Javascript,Jquery,Html Table,我正在尝试使用javascript用json中的数据填充html表(我的表有3列),但使用div方法永远无法填充数据!有人能告诉我如何使用而不使用div来填充表行的内容吗 for(i in json) { var div = "<tr id=\""+i+"\">\n" + "<td>"+i+"</td>\n" + "<td><img src=\""+ json[i].thumb +"\" height=\

我正在尝试使用javascript用json中的数据填充html表(我的表有3列),但使用div方法永远无法填充数据!有人能告诉我如何使用而不使用div来填充表行的内容吗

 for(i in json)
    {


    var div = "<tr id=\""+i+"\">\n" +
    "<td>"+i+"</td>\n" +
    "<td><img src=\""+ json[i].thumb +"\" height=\"42\" width=\"42\"></td>\n" +
    "<td>\n" +
    "<a href=\"javascript:callfunction('Name=" + json[i].title + "','" + json[i].sources + "','"+ json[i].thumb +"')\" onclick=\"selectLink(this);\">" + json[i].title + "</a><br> \n" +
    "<br></td></tr>\n\n";

    $("#myDiv").append(div);

        }
for(json中的i)
{
var div=“\n”+
“+i+”\n”+
“\n”+
“\n”+
“
\n”+ “
\n\n”; $(“#myDiv”)。追加(div); }
需要填写的表格:

   <table id="list" cellspacing="0" border="1">

    <tr>
    <th>Item#</th>
    <th>Logo</th>
    <th>Description</th>

    </tr>


    <div id='myDiv'></div>


    </table>

项目#
标志
描述
这是您的新表:

<table id="list" cellspacing="0" border="1">
  <thead>
    <tr>
      <th>Item#</th>
      <th>Logo</th>
      <th>Description</th>
    </tr>
  </thead>
  <tbody>

  </tbody>
</table>

项目#
标志
描述
和代码:

var html = '';

for(var i in json)
{
    html += '<tr id="'+i+'">'; 
    html += '<td>'+i+'</td>'; 
    html += '<td><img src="'+json[i].thumb+'" height="42" width="42"></td>';
    html += "<td>";
    html += "<a href=\"javascript:callfunction('Name=" + json[i].title + "','" + json[i].sources + "','"+ json[i].thumb +"')\" onclick=\"selectLink(this);\">" + json[i].title + "</a><br/><br/>"; 
    html += '</td>';
    html += '</tr>';
}

$('#list > tbody').html(html);
var html='';
for(json中的var i)
{
html+='';
html+=''+i+'';
html+='';
html+=“”;
html+=“

”; html+=''; html+=''; } $('#list>tbody').html(html);
这是您的新表:

<table id="list" cellspacing="0" border="1">
  <thead>
    <tr>
      <th>Item#</th>
      <th>Logo</th>
      <th>Description</th>
    </tr>
  </thead>
  <tbody>

  </tbody>
</table>

项目#
标志
描述
和代码:

var html = '';

for(var i in json)
{
    html += '<tr id="'+i+'">'; 
    html += '<td>'+i+'</td>'; 
    html += '<td><img src="'+json[i].thumb+'" height="42" width="42"></td>';
    html += "<td>";
    html += "<a href=\"javascript:callfunction('Name=" + json[i].title + "','" + json[i].sources + "','"+ json[i].thumb +"')\" onclick=\"selectLink(this);\">" + json[i].title + "</a><br/><br/>"; 
    html += '</td>';
    html += '</tr>';
}

$('#list > tbody').html(html);
var html='';
for(json中的var i)
{
html+='';
html+=''+i+'';
html+='';
html+=“”;
html+=“

”; html+=''; html+=''; } $('#list>tbody').html(html);
谢谢你的代码。它工作得很好。我可以知道用这种方式制作的表可以通过javascript代码进行搜索吗?是的,这并不重要,作为html()插入的内容也是DOM的一部分,因此jquery将毫无问题地使用它。感谢您的代码。它工作得很好。我可以知道这样制作的表可以通过javascript代码进行搜索吗?是的,这并不重要,作为html()插入的内容也是DOM的一部分,因此jquery将毫无问题地使用它。