<html>
 
<head>
 
  <title>DOM Event Examples</title>
 
  <style>
 
    #t { border: 1px solid red }
 
    #t1 { background-color: pink; }
 
  </style>
 
  <script>
 
  // Event Registration Example
 
  function l_func() {
 
    t2 = document.getElementById("t2");
 
    t2.innerHTML = "three";    
 
  }
  
  function load() {
 
    el = document.getElementById("t");
 
    el.addEventListener("click", l_func, false);
 
  }
 
  </script>
 
</head>
 
<body onload="load();">
 
<table id="t">
 
  <tr><td id="t1">one</td></tr>
 
  <tr><td id="t2">two</td></tr>
 
</table>
 
</body>
 
</html>

解决方案 »

  1.   

    <HTML>
    <HEAD>
    <TITLE>Event Listener Demo</title>
    <STYLE TYPE="text/css">
    <!--
    FORM.tb {display:inline;}
      .twidth{width:100%}
      .include{ font-size: 75%; font-family: verdana, arial, helvetica;}
      .includebig{font-family: verdana, arial, helvetica;}
      .includebig A:link { color: blue; }
      .includebig A:visited { color: purple; }
      .include  A:link { color: blue; }
      .include A:visited { color: purple; }
      .submitter { font-size: 75%; font-family: verdana, arial, helvetica; }
      .codehighlight {background:#eee}
      .WRy1{background:#fc0}
      .WRy2{background:#fff3ac}
    pre.code {color: #660099; margin-left:5%}
    address {text-align: right}
    body {background:#FFFFFF; margin-left: 5%; margin-right: 5%}
    .WRBannerCenter {margin-left:-5%; margin-right:-5%; margin-top:8px; margin-bottom:8px; text-align:center}-->
    </STYLE></HEAD><BODY>
    <DIV ID="demoDiv" STYLE="position:relative; left:100px; top:20px; width:100px; height:25px; color:blue; background-color:yellow;">Mouse over me!</DIV>
    <SCRIPT LANGUAGE="JavaScript">
    <!--
    var demoObj;
    function init() {
      demoObj = document.getElementById("demoDiv");
      demoObj.addEventListener("mouseover", colorItTan, false);
      demoObj.addEventListener("mouseout", colorItYellow, false);
    }function colorItTan() {
      demoObj.style.backgroundColor = "tan";
    }function colorItYellow() {
      demoObj.style.backgroundColor = "yellow";
    }onload = init; 
    // -->
    </SCRIPT></BODY>
    </HTML>
      

  2.   

    两种方法,
    1是调用这个控件CLICK后直行的SUB
    2 是单击这个控件 OBJECT.CLICK