急 JS 鼠标经过无法切换DIV背景图片

function starshow(1)
{
document.getElementById("ig1").style.backgroundImage='url(img/1c.png)';
}

<div id="ig1" style="width:26px;height:26px;background-image:url(img/2c.png);float:left;margin:0px;" onmouseover="starshow(1);"></div>

求解
鼠标放在div上 图片无法切换为1c.png

function starshow(1)
{
document.getElementById("ig1").style.backgroundImage='url(img/1c.png)';
}
定义方法时,不能用数字当作变量名称,所以把 starshow(1) 里面的1给改成其他变量名就好了
温馨提示:答案为网友推荐,仅供参考
第1个回答  2012-02-11
在你这个函数里面function starshow(1)是不需要传递人参数的,所以直接使用
function starshow()
{
document.getElementById("ig1").style.backgroundImage='url(img/1c.png)';
}

<div id="ig1" style="width:26px;height:26px;background-image:url(img/2c.png);float:left;margin:0px;" onmouseover="starshow();"></div>
相似回答