将ID取为相同名字,用<script language="Javascript" for=id1>来实现相同操作的功能

解决方案 »

  1.   

    <script for=pr event=onmouseover>
       thisobj=window.event.srcElement;
       thisobj.style.color="red";
    </script><script for=pr event=onmouseout>
       thisobj=window.event.srcElement;
       thisobj.style.color="";
    </script><input type=button id=pr value="Button1">
    <input type=button id=pr value="Button2">
    <input type=button id=pr value="Button3">
      

  2.   

    以下是通用的办法:
    <style>
    .navover{background-color:red}
    .navout{background-color:green}
    .navdown{background-color:blue}
    .navup{background-color:gray}
    td{background-color:#0099FF}
    </style>
    <script>
    function onMouse()
    {
    var eType=event.type.toLowerCase()
    if(event.srcElement.tagName=="TD"){
    switch(eType)
    {
    case "mouseover":
    event.srcElement.className="navover"
    break;
    case "mouseout":
    event.srcElement.className="navout"
    break;
    case "mousedown":
    event.srcElement.className="navdown"
    break;
    case "mouseup":
    event.srcElement.className="navup"
    break;
    }
    }
    }
    document.onmouseover=document.onmouseout=document.onmousedown=document.onmouseup=onMouse;
    </script>
    <table width="50%">
    <tr>
    <td>这是第一行</td>
    </tr>
    <tr>
    <td>这是第二行</td>
    </tr>
    <tr>
    <td>这是第三行</td>
    </tr>
    </table>