如何更改JavaScript数组中的背景图像网址?

时间:2014-12-20 11:37:24

标签: javascript arrays background-image

嗨,我知道这可能很简单,但我不能得到旗帜和图像的网址改变。我对JavaScript很陌生,但我已经设法让这三段文字正常工作。请帮忙! :)

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"];

1 个答案:

答案 0 :(得分:0)

尝试......

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