这段代码的ID为imgHomePage的那三个事件怎么触发不了?高手能帮我看可那问题出在哪吗?好久没编程了,现在又编起来了,都忘的差不多了,呵呵,谢啊<!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=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
<!--
body {
background-color: #B9090B;
}
.style1 {
font-size: 36px;
font-weight: bold;
color: #FFFFFF;
}
#apDiv1 {
position:absolute;
width:200px;
height:115px;
z-index:1;
left: 875px;
top: 27px;
}
.style3 {font-size: 18px}
-->
</style>
<script language="javascript" type="text/javascript">
var hp=document.getElementById("imgHomePage");
function clickHomePage(){
hp.src="homepage1.gif";
}

function clickHomePage1(){
hp.src="homepage2.gif";
}

function clickHomePage2(){
hp.src="homepage.gif";
}
</script>
</head><body>
<center>
  <p><img src="file:///D|/WebClothes/images/logo.jpg" width="300" height="150" />      </p>
  <div id="apDiv1" width="211" height="154"><img src="mao.gif" width="211" height="154" /></div>
  <table width="990" height="1105" border="0" cellpadding="0" cellspacing="0">
        <tr>
          <td width="165" height="31"><img id="imgHomePage" src="homepage.gif" width="165" height="31" alt="homepage" onmousedown="clickHomePage" onmouseover="clickHomePage1" onmouseup="clickHomePage2" /></td>
          <td width="165" height="31"><img id="imgNCHistory" src="nchistory.gif" width="165" height="31" alt="nchistory" /></td>
          <td width="165" height="31"><img id="imgNCShopping" src="ncshopping.gif" width="165" height="31" alt="ncshopping" /></td>
          <td width="165" height="31"><img id="imgNCMessage" src="ncmessage.gif" width="165" height="31" alt="ncmessage" /></td>
          <td width="165" height="31"><img id="imgAboutNC" src="aboutnc.gif" width="165" height="31" alt="aboutnc" /></td>
          <td width="165" height="31"><img id="imgNCAdvertisement" src="ncadvertisement.gif" width="165" height="31" alt="ncadvertisement" /></td>
        </tr>
        <tr>
          <td height="950" colspan="6" bgcolor="#000000">&nbsp;</td>
        </tr>
        <tr>
          <td colspan="6"><div align="center" class="style1">
            <p>&nbsp;</p>
            <span class="style3">Home Page | NC History | NC Shopping | NC Message | About NC | NC Advertisement</span>
            <p class="style3">&nbsp;</p>
            <p class="style3">Copyright by 2009 3 13</p>
          </div></td>
        </tr>
      </table>
  <p>&nbsp;  </p>
</center>
</body>
</html>

解决方案 »

  1.   

    要了解事件绑订的本质:
    onmousedown,onmouseover,onmouseup他们是组件的一个属性,就像name,id一样,他们的值可以是任何类型,像你的那种写法,其实是把字符串赋值给onmousedown,onmouseover,onmouseup这些属性,我们要让这个组件对鼠标事件有响应,就应该把function赋值给他们。
    这样写:
     <img id="imgHomePage" src="homepage.gif" width="165" height="31" alt="homepage" onmousedown=clickHomePage onmouseover=clickHomePage1 onmouseup=clickHomePage2 /> 
    九可以了。
    因为
    function clickHomePage1(){ 
    hp.src="homepage2.gif"; 
    }
    本质上是创建了一个变量,名字叫作 clickHomePage1, 它指向一个Function对象,这个Function对象的内容是{ 
    hp.src="homepage2.gif"; 
    }
      

  2.   

    onmousedown="clickHomePage()" onmouseover="clickHomePage1()" onmouseup="clickHomePage2()"  要加括号另外hp.src 这里的hp没有对象,你可以建一个图片标签ID为hp
    如:<img id="hp" src="" border="0"/>
      

  3.   


    <!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=utf-8" /> 
    <title>Untitled Document </title> 
    <style type="text/css"> 
    <!-- 
    body { 
    background-color: #B9090B; 

    .style1 { 
    font-size: 36px; 
    font-weight: bold; 
    color: #FFFFFF; 

    #apDiv1 { 
    position:absolute; 
    width:200px; 
    height:115px; 
    z-index:1; 
    left: 875px; 
    top: 27px; 

    .style3 {font-size: 18px} 
    --> 
    </style> 
    <script language="javascript" type="text/javascript"> 
    var hp=document.getElementById("imgHomePage"); 
    function clickHomePage(){ 
    document.getElementById("hp").src="http://www.hao123.com/logo.gif"; 
    } function clickHomePage1(){ 
    document.getElementById("hp").src="http://www.hao123.com/images/guangg/ct10000.gif"; 
    } function clickHomePage2(){ 
    document.getElementById("hp").src="http://www.hao123.com/images/guangg/ct10000.gif"; 

    </script> 
    </head> <body> 
    <center> 
      <p> <img src="http://zi.csdn.net/300x60_3.gif" id="hp" width="300" height="150" />      </p> 
      <div id="apDiv1" width="211" height="154"> <img src="mao.gif" width="211" height="154" /> </div> 
      <table width="990" height="1105" border="0" cellpadding="0" cellspacing="0"> 
            <tr> 
              <td width="165" height="31"> <img id="imgHomePage" src="homepage.gif" width="165" height="31" alt="homepage" onmousedown="clickHomePage()" onmouseover="clickHomePage1()" onmouseup="clickHomePage2()" /> </td> 
              <td width="165" height="31"> <img id="imgNCHistory" src="nchistory.gif" width="165" height="31" alt="nchistory" /> </td> 
              <td width="165" height="31"> <img id="imgNCShopping" src="ncshopping.gif" width="165" height="31" alt="ncshopping" /> </td> 
              <td width="165" height="31"> <img id="imgNCMessage" src="ncmessage.gif" width="165" height="31" alt="ncmessage" /> </td> 
              <td width="165" height="31"> <img id="imgAboutNC" src="aboutnc.gif" width="165" height="31" alt="aboutnc" /> </td> 
              <td width="165" height="31"> <img id="imgNCAdvertisement" src="ncadvertisement.gif" width="165" height="31" alt="ncadvertisement" /> </td> 
            </tr> 
            <tr> 
              <td height="950" colspan="6" bgcolor="#000000">&nbsp; </td> 
            </tr> 
            <tr> 
              <td colspan="6"> <div align="center" class="style1"> 
                <p>&nbsp; </p> 
                <span class="style3">Home Page | NC History | NC Shopping | NC Message | About NC | NC Advertisement </span> 
                <p class="style3">&nbsp; </p> 
                <p class="style3">Copyright by 2009 3 13 </p> 
              </div> </td> 
            </tr> 
          </table> 
      <p>&nbsp;  </p> 
    </center> 
    </body> 
    </html>
      

  4.   

    im so sorry, 搞错了,楼上正解!
      

  5.   


    <script language="javascript" type="text/javascript"> function clickHomePage(){ 
    var hp=document.getElementById("imgHomePage"); 
    hp.src="homepage1.gif"; } function clickHomePage1(){ 
    var hp=document.getElementById("imgHomePage"); 
    hp.src="homepage2.gif"
    } function clickHomePage2(){ 
    var hp=document.getElementById("imgHomePage"); 
    hp.src="homepage.gif"; 

    </script> 在引用是注意得加上(),如:
    <img id="imgHomePage" src="homepage.gif" width="165" height="31" alt="homepage" onmousedown="clickHomePage();" onmouseover="clickHomePage1();" onmouseup="clickHomePage2();"/> 
    如果使用如下函数更高效:
    function clickHomePage2(objID,src){ 
    var o=document.getElementById(objID); 
    o.src=src; 
    }
    对象的ID号和图片的路径作为参数传递给函数,然后在各个事件中调用即可