直接给图片添加onmouseover事件,更换src
解决方案 »
- 如何判断网页文档加载完毕?
- JavaScript 重载问题
- 求助,关于innerHTML~
- ■■现金200元,问IE问题,挑战自我!
- 求javascript 防止客户端学习挂机脚本
- fushionchart如何在java代码生成图片,我知道jfreechart可以,还有,如何打印带fushionchart的html页面,不用activeX
- js Settimeout 精度问题
- 表格中当滚动横向滚动条时,表格头部跟着移动,滚动纵向滚动条时表格头部固定,怎样实现???
- 在线等:怎么自动将服务器上的多个图片保存到本地计算机的指定目录下?
- 此句为何意?
- 四层效果叠加的实现问题,有图,诚恳求教
- 关联数组 能够 倒序 排列么?
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无dfdf</title>
</head><body>
<script language="javascript">
function mychange()
{
document.getElementById("tag1").src="image/7.jpg";
}
function mychange1()
{
document.getElementById("tag1").src="image/6.jpg";
}
</script>
<table width="600" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="300" height="40" bgcolor="#009966" >
<a href="2.html" >
<img id="tag1" src="image/6.jpg" width="194" height="35" border="1"
onmousemove="mychange()" onmouseout="mychange1()"/>
</a>
</td>
<td width="300"> </td>
</tr>
</table>
</body>
</html>
以上代码经过调试的,希望能帮助你
直接设置td的innerHTML<script language="javascript">
function mychange(td)
{
tdinnerHTML="<a href="index.jsp" id="tag1"><img src="images/ban6.jpg" width="194" height="35" border="0" /></a>";
}
</script>
<table width="600" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="300" height="40" bgcolor="#009966" onmouseover="mychange(this)"><a href="index.jsp" id="tag1"><img src="images/ban5.jpg" width="194" height="35" border="0" /></a></td>
<td width="300"> </td>
</tr>
</table>
function mychange()
{
document.getElementById("tag1").innerHTML="<img src='images/ban6.jpg' width='194' height='35' border='0' />";
}
</script>这样写不是很好。
分析一下
<td width="300" height="40" bgcolor="#009966" onmouseover="mychange()"><a href="index.jsp" id="tag1"><img src="images/ban5.jpg" width="194" height="35" border="0" /></a></td>这个,其他都一样,其实只需要改一下 src="images/ban5.jpg" 这个就可以了那么就可以改为
js部分:function mychange()
{
var picsrc=document.getElementById("tu");
picsrc.setAttribute("src","images/ban6.jpg");
}
修改他的图片地址属性就可以了
html部分,给img加上ID:<td width="300" height="40" bgcolor="#009966" onmouseover="mychange()"><a href="index.jsp" id="tag1"><img id="tu" src="images/ban5.jpg" width="194" height="35" border="0" /></a></td>
这句代码相当于是给你的超链接标签<a>设置的文本内容、
直接将改期属性src,即可。。
function mychange()
{
var picsrc=document.getElementById("tu");
picsrc.setAttribute("src","images/ban6.jpg");
var piclink=document.getElementById("tag1");
piclink.setAttribute("href","index2.jsp");
}
这样就可以了这代码量总比你的innerhtml要短上不少吧,而且兼容性好,可读性强,不容易出错,有些浏览器还不兼容innerHTML呢。