<body onmouseover=mouseover()>
<input type=text name=txt1>
<input type=text name=txt2>
<script>
function mouseover()
{    alert(event.srcElement.name)
}
</script>
</body>

解决方案 »

  1.   

    我想获得当前鼠标的位置,然后判断是否在某个控件里面,怎么做?
    楼上这位大虾的脚本我试过了,好像对于table a 这样的对象不好
    用!!
      

  2.   

    那是因为你没有给table和a取name
      

  3.   

    马马乎乎用用
    <html><head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <meta name="GENERATOR" content="Microsoft FrontPage 4.0">
    <meta name="ProgId" content="FrontPage.Editor.Document">
    <title>New Page 1</title>
    </head><body onmouseover=mouseover()>
    <input type=text name=txt1 >
    <input type=text name=txt2 > 
    <script> 
    function mouseover()
    {
    if(window.event.clientX>txt1.offsetLeft && window.event.clientX<txt1.offsetLeft+txt1.offsetWidth && window.event.clientY>txt1.offsetTop && window.event.clientY<txt1.offsetTop+txt1.offsetHeight)
        alert(event.srcElement.name)
    }
    </script>
    </body></html>
      

  4.   

    關于Table的情況你能怎樣呢?當鼠標屬于某個TD時也同時屬于TABLE﹐還有其他包含方式的標簽判斷鼠標的位置有屬性
    event.clientX和event.clientY不如設一個全局變量﹐然后在onmouseover中把名稱傳給該變量var activeE=''
    document.onmouseover=fucntion(){activeE=event.srcElement.name}
      

  5.   

    <body onmouseover=mouseover()>
    <table border=1 id=a1>
    <tr><td><input type=text name=txt1></td>
    <td><input type=text name=txt2></td></tr>
    </table>
    <script>
    function mouseover()
    {
       alert(a1.contains(document.elementFromPoint(event.clientX,event.clientY)))
    }
    </script>
    </body>