在html页面中有10张图片 分别放在10个不同的td里(td中含有id如:id="bg0"),用IE打开html页面,鼠标滑过图片时,背景图片变大,移开变回原来的。现在因为取不到mouseover触发图片的id,在js中需要写了10个如下的函数,这样很麻烦,有没有什么方法取到mouseover触发图片的id,简化js?
function mouseOver()
{
document.getElementById("bg"+0).style.backgroundImage=img[0];
}
function mouseOut()
{
document.getElementById("bg"+0).style.backgroundImage=img[1];
}
function mouseOver()
{
document.getElementById("bg"+0).style.backgroundImage=img[0];
}
function mouseOut()
{
document.getElementById("bg"+0).style.backgroundImage=img[1];
}
event.srcElement.id
<td onmouseover="mouseOver(this)" onmouseout="mouseOut(this)"></td>function mouseOver(obj)
{
obj.style.backgroundImage=img[0];
}
function mouseOut(obj)
{
obj.style.backgroundImage=img[1];
}