2013-12-09 93 views
0

我需要關於這種情況的幫助。 我目前從JSON導入數據,而對於照片字段,我所獲得的只是該圖像的鏈接。將鏈接更改爲圖片

是否有可以改變任何模塊/其它方法 這

http://example.com/images/abc-123.jpg 

<img src="http://example.com/images/abc-123.jpg" /> 

,或讓他們直接閱讀的鏈接,並切換到圖像顯示?

附加信息:

下面是現場顯示的結構。

<div class="field"> 
    <div class="field-items"> 
     <div class="field-item even"> 
      <p> 
       <a href="http://example.com/images/abc-123.jpg">http://example.com/images/abc-123.jpg 
       </a> 
      </p> 
     </div> 
     <div class="field-item odd"> 
      <p> 
       <a href="http://example.com/images/efg-123.jpg">http://example.com/images/efg-123.jpg 
       </a> 
      </p> 
     </div> 
     ........... for multiple link 
    </div> 
</div> 
+0

你在哪裏收到這個JSON數據?在你的PHP代碼或HTML/Javascript方面? –

+0

使用JSON解析器模塊的HTML/Javascript端。 – Kooki3

回答

0

如果你正在處理的Javascript的JSON數據,然後..

var image_url = data.image_url; // assuming data.image_url gives us the url to the image 
var html_for_image = "<img src='" + image_url + "' />"; 
// if you are using jQuery 
$('#image_element_placeholder').html(html_for_image); 
// else if you are using plain JS 
var placeholder = document.getElementById('image_element_placeholder'); 
placeholder.innerHTML = html_for_image; 

Hope這有助於。

+0

我必須在JSON源代碼中執行這些操作嗎?或者在目的地(drupal)? – Kooki3

+0

目的地,請。 –

+0

作品,非常感謝。 – Kooki3

0

試試這個,沒必要方法

例如

鏈路處於可變

$link = http://example.com/images/abc-123.jpg 

echo "<img src=" . $link . " />"; 
+0

適用於單一數據,但適用於多頁數據。不那麼方便。 – Kooki3