我試圖使用JavaScript設置<img>
src
,但圖像缺少可視化效果;它是空的。運行此代碼後的圖像URL以"http://127.0.0.1:8080/%27"
(我甚至不知道這是從哪裏來的)開始,而不是"data: image/png"
。變量mySrc
被設置爲Base64編碼的圖像。設置<img> src轉換爲使用Javascript的Base64編碼圖像失敗
document.getElementById(id).src="'"+mySrc+"'";
這就是URL的樣子設置之後:
http://127.0.0.1:8080/%27data:image/png;base64,/9j/4AAQSkZJRgABAQEAYABgAAD/4RMNRXhpZgAASUkqAAgAAAAQAAABAwABAAAAuAsAAAEBAwABAAAA9gkAAAIBAwADAAAAzgAAAAMBAwABAAAAAQAAAAYBAwABAAAAAgAAAA4BAgAfAAAA1AAAABIBAwABAAAAAAAAABUBAwABAAAAAwAAABoBBQABAAAA9AAAABsBBQABAAAA/AAAABwBAwABAAAAAQAAACgBAwABAAAAAgAAADEBAgALAAAABAEAADIBAgAUAAAAEAEAADsBAgAEAAAAUm9uAGmHBAABAAAAJAEAAHwBAAAIAAgACABJbWFnZSBjb252ZXJ0ZWQgdXNpbmcgaWZmdG9hbnkAAMDGLQAQJwAAwMYtABAnAABQaWNhc2EgMy4wAAAyMDA4OjA2OjA2IDEwOjM2OjEyAAQAAaADAAEAAAD...
無從得知,沒有看到更多的代碼,比如如何定義並填充「mySrc」。 – Chad 2011-12-21 19:29:05