2016-11-13 20 views
0

我想動態地顯示混合應用程序上的圖像。我的意思是圖像位於服務器上,我正在Cordova應用上顯示它們。attr在其他域的圖像不工作在科爾多瓦

我在頭部添加了cordova和jquery。 這是代碼。

var pics = "http://www.test.com/img/53_20160713104002.png"; 

     document["profile-pic"].src = pics; 
     $("#profile-pic").attr("src", pics); 

這裏是html代碼。

<a href="profile.html" data-original-title="" title=""> 
    <img width="35" height="30" id="profile-pic" class="profile img-circle" name="profile-pic" /></a> 

請告知我做錯了什麼。

編輯:這似乎是問題是由於跨域。我有白色列出配置文件中的域。

+0

它似乎工作:https://jsfiddle.net/8jwqL6s4/ – Alvaro

+1

它是在瀏覽器中正常工作,而不是在移動應用程序或模擬器。 – Ironic

+0

@CalculatingMachine你可以檢查jQuery是否在移動設備上工作?你使用什麼版本? –

回答

1

感覺像jQuery不適用於Cordova應用程序。嘗試使用:

var pics = "http://www.test.com/img/53_20160713104002.png"; 

document["profile-pic"].src = pics; 
document.getElementById("profile-pic").setAttribute("src", pics); 

如果上面的代碼有效,那麼您必須找出爲什麼jQuery不在Cordova中工作。

一些指點下一個問題:

+0

thnks爲您的答案。讓我嘗試。 – Ironic

+0

等待結果... @CalculatingMachine ... –

+0

無法正常工作。沒有圖像加載。 – Ironic