直接给图片添加onmouseover事件,更换src

解决方案 »

  1.   

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <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">&nbsp;</td>
      </tr>
    </table>
    </body>
    </html>
    以上代码经过调试的,希望能帮助你
      

  2.   

    src的方法固然可行,也试过。但如果换地址的话,还要换href,非常麻烦。难道就没有一次替换的好办法吗
      

  3.   


    直接设置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">&nbsp;</td>
      </tr>
    </table>
      

  4.   

    我今天试了试,发现只要obj.innerHMTL语句后有html标签的话,链接就不能正常跳转,LZ可以动态创建一个img标签,然后加载<a>后面,试试
      

  5.   

    <script language="javascript">
    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>
      

  6.   

    document.getElementById("tag1").innerHTML、、
     这句代码相当于是给你的超链接标签<a>设置的文本内容、
     直接将改期属性src,即可。。
      

  7.   

    如果还要改链接就是
    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呢。