简体   繁体   中英

How do I change backgroundImage url in JavaScript array?

Hi I know that this is probably simple but I just cant get the url of the flag and the image to change. I'm pretty new to JavaScript but i've managed to get the three pieces of text working. Help please! :)

function changeinfo(person){
    document.getElementById("personname2").innerHTML = window[person][0];
    document.getElementById("country2").style.backgroundImage = "url('')", [1];
    document.getElementById("image2").style.backgroundImage = "url('')",[2];
    document.getElementById("ratingnum3").innerHTML = window[person][3];
    document.getElementById("ratingnum4").innerHTML = window[person][4];
}

var tango = ["Tango",
    'flags/uk.png', 
    "images/tango.jpg", 
    "2", 
    "3"];

Try ...

document.getElementById("country2").style.backgroundImage = "url('" + window[person][1] + "')";
document.getElementById("image2").style.backgroundImage = "url('" + window[person][2] + "')";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM