我使用Visual Studio + Cordova + AVD + jQueryMobile。在jQuery Mobile中設置圖像src不起作用
使用cordova-plugin-camera和cordova-plugin-file我得到一張照片。它返回像一個路徑:
file:///storage/emulated/0/Android/data/io.cordova.myapp66b652/cache/1491727086753.jpg
我還可以使用resolveLocalFileSystemURL
功能,以獲得更相對路徑:
/1491727086753.jpg
每當我試圖設置一個現有的圖像標籤的src
:
var elem = document.getElementById('source-preview');
elem.src = fullCameraPath; // file:///storage/emulated/0/Android/data/io.cordova.myapp66b652/cache/1491727086753.jpg
// or
elem.src = fileEntry.fullPath; ///1491727086753.jpg
// or
$('#source-preview').attr('src', ...);
<img id="source-preview" style="width: 100%;" />
以上方法都不會失敗,但HTML元素未被修改且圖像不顯示。再次調用.src的確顯示了在那裏推送的路徑。只有.attr('src', ...)
足夠說: Failed to load resource: net::ERR_FILE_NOT_FOUND
這表明存在問題。
然而,如果我手動在調試器編輯HTML到:正確
<img id="source-preview" style="width: 100%;" src="file:///storage/emulated/0/Android/data/io.cordova.myapp66b652/cache/1491727086753.jpg" />
圖像顯示器。然而,使用由科爾多瓦 - 插件文件所提供的更短的路徑不起作用:
<img id="source-preview" style="width: 100%;" src="file:///1491727086753.jpg" />
這似乎在告訴我,像存在,但jQuery Mobile的是由於某種原因拒絕接受(如某種「安全檢查「)加載它。
任何幫助將不勝感激。
經過進一步處理,麻木不仁,測試它似乎沒有JS編輯呈現在圖像標籤上。如果我使用完全相同的代碼執行'.append()',則也會顯示工作映像。看起來有一些與jQueryMobile刷新錯誤,但沒有發現有關這方面的文章有幫助。 – Origin