我想在javascript函數中更改html文檔背景圖像,但我遇到了一些困難。這是我有:在javascript函數中更改文檔背景圖像
function changeBgImage(){
document.background = "url('images/SecondBackground.png')";
}
但正如我所說,不工作..任何想法?
我想在javascript函數中更改html文檔背景圖像,但我遇到了一些困難。這是我有:在javascript函數中更改文檔背景圖像
function changeBgImage(){
document.background = "url('images/SecondBackground.png')";
}
但正如我所說,不工作..任何想法?
使用
document.body.style.backgroundImage = "url('images/SecondBackground.png')";
你接近,但你需要。體爲好。
document.body.style.background = "url('images/SecondBackground.png')";
function changeBGImage() {
document.body.style.backgroundImage = "url(http://images.cheezburger.com/completestore/2010/7/9/fe8e91c5-c3f1-40cf-a034-983e8683ba73.jpg)";
};
這會做到這一點!
@ Neurofluxation - 哈哈!懸停喇嘛:) – Tiwaz89
:D ohhhh yeahhhhhh –
嘗試是這樣的
document.getElementById("id of body").setAttribute("style","background-url:'images/SecondBackground.png'")
,完美的工作:)謝謝@Amol Kolekar – Tiwaz89
歡迎您.. :) –