2014-11-04 62 views
0

我試圖做到以下幾點:如何HTML DIV追加到表響應的jQuery的getJSON

$.getJSON("script/course_session.php", data, function(data) { 
$.each(data, function(i, item) { 

    var $tr = $('<tr>').append(
     $('<td>').text(item.start_date + " - " + item.end_date), 
     $('<td>').text(
      '<div class=&quot;col-md-3 btn-buy animated fadeInRight&quot;><a href=&quot;#&quot; class=&quot;btn-u btn-u-sm enroll-button&quot;><i class=&quot;fa fa-university&quot;></i> Register</a></div>') 
    ).appendTo("#session-table"); 
}); 
}); 

的目的是實現類似如下(我使用的引導):

enter image description here

然而,這是它得到的打印方式: enter image description here

什麼是仁的正確方法der html?

回答

1

您必須使用.html(...)而不是.text()。而「代替QUOT;

-1

.html()

A string of HTML to set as the content of each matched element. 

.text()

The text to set as the content of each matched element. When Number or Boolean is supplied, it will be converted to a String representation. 

的區別是.html(str)str的轉換爲DOM如果str有標籤內容和.text()必須轉換str即使str包含XML或html。