javascript 小小的问题

来源:百度知道 编辑:UC知道 时间:2024/05/22 14:55:33
我想通过javacript来改变 <a>标签的背景图片
前提是当我用鼠标指上去的时候显现图片,当鼠标移动走时就不显示图片了,该怎么写javascript 代码?????
希望有个代码??
<script language="javascript">
function showimge()
document.getElementById("dh1").style.background="url(animal/onmouseover.gif)"
}
function hiddenimge()
{
document.getElementById("dh1").style.background="url(animal/onmouseout.gif)"
}
//-->
</script>
<a href="http://www.baidu.com" id="dh1" onmouseover="showimge()" onmouseout="hiddenimge()">新疆</a>
这样写为什么不对啊??????

如果不想在<a></a>标签对中加入鼠标事件,可以考虑在页面加载的时候初始化onmouseover和onmouseout两个事件

给<a></a>加个ID属性 <a id="linkMyAddress" href=".....">go</a>

function linkAction() {
var oLink = document.getElementById("linkMyAddress");
oLink.onmouseover = function() {
this.style.background="url('picture.gif')";
};
oLink.onmouseout = function () {
this.style.background="";
};
}

<body onload="linkAction()">

用鼠标事件就可以实现吧..

<a href="javascript:" onmouseover="this.style.background='url(pic.gif)'" onmouseout="this.style.background=''">test</a>

这么简单的问题就不需要脚本了吧
样式表。。。。
<style>
a{}
a:hover{background:url('picture.gif') no-repeat center center}
</style>
<a href="#">asdfaaf</a&g