A C*_*nge 1 html javascript image function src
我有一个函数getImgurUrl(),我希望它返回的是img标记的src值.
我怎样才能做到这一点?
我的功能:
function getImgurUrl() {
//get imgur url for current image
var cookieArray = document.cookie.split(";");
var encodedURL = cookieArray[2].split("=");
var decodedURL = decodeURIComponent(encodedURL[1]);
return decodedURL;
}
Run Code Online (Sandbox Code Playgroud)
和img标签:
<img id="image" name="image" src="" alt="If you're seeing this something is wrong.">
Run Code Online (Sandbox Code Playgroud)
window.onload = function() {
document.getElementById("image").src = getImgurUrl();
};
Run Code Online (Sandbox Code Playgroud)