2017-01-03 48 views
-1

我想使用圖像src中的變量在表格單元格中顯示圖像。 我顯示我的文本數據如下,但我沒有在桌子上顯示圖像。如何使用JavaScript在HTML表格中顯示圖像?

var div = document.getElementById('packsTable'); 

     $.each(childData, function(key, item) { 
      ImageUrl = "Brush_Basic1.png"; 
      var typeName = childData[key]; 
      div.innerHTML = div.innerHTML + '<td>'+key+'</td>' 
         + '<td>'+childData[key].ID+'</td>' 
         + '<td>'+childData[key].LOCK+'</td>' 
         + '<td>'+childData[key].LOCKED+'</td>' 
         + '<td>'+childData[key].PLAYSTORE+'</td>' 
         + '<td>'+childData[key].THUMBNAIL+'</td>' 
         + '<td>'+childData[key].TR+'</td>' 
         + '<td>'+ImageUrl+'</td>' 
         + '<td>'+attr("src", ImageUrl)+'</td></div>'; 
     }) 

如何在表格中顯示圖像。

+1

凡定義的'attr'功能?你期望它做什麼? – Quentin

回答

2

如果我是正確的,你試圖在你的HTML表格中顯示圖像?那好吧,你 必須創建一個IMG HTML元素<img src="'+ImageUrl+'"></img>所以像:

$.each(childData, function(key, item) { 
      ImageUrl = "Brush_Basic1.png"; 
      var typeName = childData[key]; 
      div.innerHTML = div.innerHTML + '<td>'+key+'</td>' 
         + '<td>'+childData[key].ID+'</td>' 
         + '<td>'+childData[key].LOCK+'</td>' 
         + '<td>'+childData[key].LOCKED+'</td>' 
         + '<td>'+childData[key].PLAYSTORE+'</td>' 
         + '<td>'+childData[key].THUMBNAIL+'</td>' 
         + '<td>'+childData[key].TR+'</td>' 
         + '<td>'+ImageUrl+'</td>' 
         + '<td><img src="'+ImageUrl+'"></img></td></div>'; 
     }) 
+0

它的工作原理。謝謝。 – isuru