我有一个javascript文档,我正在获取一个json对象,我想创建div,因为我可以在json数组上拥有多个实例。我正在创建一篇文章,更改他的innerHTML并将其添加到正文中,但它不会被添加。
$.ajax({
url: 'myURL',
type: "GET",
data: query,
dataType: 'json',
success: function (data) {
alert(data);
for (var i = 0; i < data.length; i++)
{
var _body = document.getElementsByTagName('body') [0];
alert(_body.innerHTML);
var article = document.createElement('article');
article.id = 'invoiceno'+i;
article.innerHTML = '<div id="client"></div><table class="cabecalho"><tr><th><span>Invoice #</span></th><td id="invoiceno"><span>invoiceno</span></td></tr><tr><th><span>Date</span></th><td id="invoicedate"><span>invoicedate</span></td></tr></table><table class="total"><tr><th><span >Total</span></th><td><span data-prefix>€</span><span id="tots">(TotalAPagar)</span></td></tr></table>';
alert(article.innerHTML);
_body.appendChild(article);
$("#invoiceno"+i).html(data[i].InvoiceNo);
$("#invoicedate"+i).html(data[i].InvoiceDate);
$("#client"+i).html(data[i].CompanyName);
$("#tots"+i).html(data[i].GrossTotal);
}
}
});