私は作業コードを持っています。これは無作為にbody
の背景を私のgifで変更します。JSとの背景のランダム化
var totalCount = 11;
function ChangeIt() {
var num = Math.ceil(Math.random() * totalCount);
document.body.background = '/static/img/'+num+'.gif';
document.body.style.backgroundRepeat = "repeat";
}
window.onload = ChangeIt;
ここでは、別のHTML要素、たとえばdivの1つと一緒に使用したいと考えています。 document.body.background
〜document.getElementById('id').background
を変更しても機能しません。コードをどのように変更すればよいですか?
私はこれが助けになると思う:http://stackoverflow.com/questions/15295381/javascript-change-element-background – Zze