js根据ID修改背景图片

<SCRIPT language=javascript>
function expand(el)
{
var childObj = document.getElementById("child" + el);
var box = document.getElementById("box");
if (childObj.style.display == 'none')
{
childObj.style.display = 'block';
box.style......//按照上面的写法就可以了
}
else
{
childObj.style.display = 'none';
}
return;
}
</SCRIPT>
追问
不行啊!
回答
box.style.background='****.jpg no-repeat';
这样不行?
提问者评价
太谢谢了  box.style.background='url(images/menu_bt.jpg) no-repeat';  这样写就可以了   我先前写错了
<SCRIPT language=javascript>
function expand(el)
{
var childObj = document.getElementById("child" + el);
var box = document.getElementById("box");
if (childObj.style.display == 'none')
{
childObj.style.display = 'block';
box.style......//按照上面的写法就可以了
}
else
{
childObj.style.display = 'none';
}
return;
}
</SCRIPT>
追问
不行啊!
回答
box.style.background='****.jpg no-repeat';
这样不行?
提问者评价
太谢谢了  box.style.background='url(images/menu_bt.jpg) no-repeat';  这样写就可以了   我先前写错了
原文地址:https://www.cnblogs.com/Bouger/p/4381375.html