js传参的问题

来源:百度知道 编辑:UC知道 时间:2024/06/22 06:14:04
<script>
function changebg(menuID,url)
{
document.all.menuID.style.background="URL("+url+")";
}
</script>

<div id="menuTitle1" class="title" onmousemove="changebg(menuTitle1,'/imgae/wp17.jpg')"></div>

document.all.menuID.style.background要报错
不知道怎样获取div的id

去掉document.all.就可以
------------------------------
<script>
function changebg(menuID,url)
{
menuID.style.background="URL("+url+")";
}
</script>

<div id="menuTitle1" class="title" onmousemove="changebg(menuTitle1,'/imgae/wp17.jpg')"></div>

document.getElementById('xxx');
xxx为div的id

var divId=document.getElementById("menuTitle1");