如果网页中有一个文本框 <input type="text" id="text1" />我该如何用 Javascript或jQuery 来判断这个文本框,当前是否是取得焦点的状态?(即是否被 focus 了)另外,如果有一个 <div id="div1">mydivTest</div>我该如何用 Javascript或jQuery 来判断当前是否鼠标正在 mouseover 它?望高手不吝赐教,100分求解,万分感谢了。最后,祝大家2010中国年快乐。

解决方案 »

  1.   

    <input id="searchbox" type="text" value="鼠标如果点在上面的话字就消失,和楼主的意思相近" onfocus="javascript:this.value=''" />
      

  2.   

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <base href="http://docs.jquery.com" />
    <script src="http://code.jquery.com/jquery-latest.js"></script>
     
    <script>
    window.onload = (function(){
    var obj;
    $("#text1").focus( function () {
    alert("getFocus!"); 
    });
    $("#div1").mouseover(function(){
    alert("mouseover!");
    });
    });
    </script>
    </head>
    <body>
    <button>check</button>
    <input type="text" id="text1" /> 
    <div id="div1">mydivTest </div> 
    </body>
    </html>
      

  3.   

    if(document.activeElement == 文本框对象) alert('获得焦点');$(document).mouseover(function (e) {
        if(e.target == $('#div1')[0]) alert('i am here');
    });