jQuery appended table adds closing tag at the end of the text automatically. Why?

前端 未结 4 732
旧时难觅i
旧时难觅i 2020-12-06 14:49
$(\'#all_locations\').append(\"\");
$(\'#all_locations\').append(\"\");

$.each(data, function(i, item){
          
4条回答
  •  遥遥无期
    2020-12-06 15:17

    Instead of doing it that way, try something like this:

    var table = $("
City
"); if (table){ table.append($("").append($("").append($(""); $.each(data, function(i, item){ $('#all_locations').append(""); $('#all_locations').append(""td>"); $('#all_locations').append(""}); } $("#all_locations tr").wrapAll("
").text("City"))); $.each(data, function(i, item){ table.append($("
").text(item.city))); }); table.appendTo($("#all_locations")); }

Here's another way that's closer to how you're currently doing it:

$("#all_locations""#all_locations").append("
City
""
" + item.city + "
");

提交回复
热议问题