当鼠标放到图片上时,图片变换
 
  function mouseOver(id){
      alert(document.getElementById(id).src);
      document.getElementById(id).src='images/navigation/3_08.png';
  }  <a href="index.htm" onMouseOver="mouseOver(1)">
        <img src="images/navigation/3_08.png" id="1">
   </a>
 
  到alert时 出来为定义,为什么?

解决方案 »

  1.   

    函数最后一行的分号你用了全角的,因此函数有错误,改了就好了。
    <script>  function mouseOver(id){ 
          alert(document.getElementById(id).src); 
          document.getElementById(id).src='images/navigation/3_08.png'; 
      } 
    </script>
       <a href="index.htm" onMouseOver=";mouseOver(1);"> 
             <img src="images/navigation/3_08.png" id="1"> 
        </a> 另外最好不要用数字直接做id 
      

  2.   

    应该是没有获取到页面元素。
    你可以把代码放到生产那个"id"的后边,或者在window.onload中加载脚本
      

  3.   

      function mouseOver(id){ 
          alert(document.getElementById(id).src); 
          document.getElementById(id).src='images/navigation/3_08.png'; 
      } 这句外面的<script> 加上个属性
    <script language="javascript" type="text/javascript" defer="defer">
      function mouseOver(id){ 
          alert(document.getElementById(id).src); 
          document.getElementById(id).src='images/navigation/3_08.png'; 
      } 
    </script>
      

  4.   


    <script language="javascript" type="text/javascript" defer="defer">
      function mouseOver(id){ 
          alert(document.getElementById(id).src); 
          document.getElementById(id).src='images/navigation/3_08.png';
      } 
    </script>重发一下  还有全角没改
      

  5.   

    怎么这么多错  怪我太疏忽哈id这个参数要是字符串传图片的id的话
    就要这么写
    <script language="javascript" type="text/javascript" defer="defer">
      function mouseOver(id){ 
          alert(document.getElementById(id).src); 
          document.getElementById(id).src='images/navigation/3_08.png';
      } 
    </script>
       <a href="index.htm" onMouseOver="mouseOver(’1‘)"> 
             <img src="images/navigation/3_08.png" id="1"> 
        </a> 要是还不行 id改改名字看看  1这个数字做id没用过
      

  6.   


       <a href="index.htm" onMouseOver="mouseOver(’1‘)"> 
             <img src="images/navigation/3_08.png" id="1"> 
        </a> 本想强调一下的  没想到没出来 mouseOver(’1‘)  注意那俩单引号