如题,比如当前焦点在一个textfield的上面,我能否得到这个元素的信息如id
请写出代码  谢谢

解决方案 »

  1.   

    获得焦点时触发事件传入参数为当前元素。
    <html>
    <head>
    <script type="text/javascript">
    function findIt(obj) {
    alert(obj.id + ' : ' + obj.name);
    }
    </script>
    </head>
    <body>
    <input type="text" id="sun" name="nus" onfocus="findIt(this);" />
    </body>
    </html>
      

  2.   

    <!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>无标题文档</title>
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
    <script>
    $(function(){
      var idname= $(".a").attr("id");
      alert(idname);
      })
    </script>
    </head><body>
    <input id = "我是ID" class="a" name="11" type="text" /></body>
    </html>
      

  3.   

    不知道楼主是不是这个意思?确定是确定是获得焦点,不是onmouseover?
      

  4.   

    var actId = document.activeElement.id;actId  就是当前获得焦点元素的ID
      

  5.   

    完全可以啊  ‘
    getAttribute("id");//js的方法
    或者JQUERY
    $("input").focus(function(){
       $(this).attr("id");
    });