2015-04-03 45 views

回答

3

只需添加的東西,你的DIV ID和在jQuery選擇 「#something」 添加使用JavasScript。

CSS:

#something { 
    width: 600px; 
    height: 400px; 
    border: 1px solid; 
} 

jQuery選擇:

$("#something").css("background", "url(" + images[Math.floor(Math.random() * images.length)] + ")"); 

集ID到div:

<div id="something"></div> 

JSFiddle

+0

是的,但圖像被打破,你檢查後,它不拉圖片:/ – Nec 2015-04-03 08:28:02

+0

現在似乎工作,非常感謝你:) – Nec 2015-04-03 08:30:25

1

嘗試

<div id="something"></div> 

和JavaScript部分

$("#something").css("background", "url(" + images[Math.floor(Math.random() * images.length)] + ")");