页面上的文本输入框,在焦点离开后,检查用户输入的数据。
因为使用鼠标和使用键盘我的程序处理不一样,所以请问:在onfocusout事件中,有没有参数指明,是按键盘TAB,还是鼠标点在别的输入框中触发的?

解决方案 »

  1.   

    做了个例子,lz参考下吧,希望对lz有用^_^
    <html><head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>新建网页 5</title>
    <script>
    function aaa(obj){
    if(typeof(obj.hasblur)=='undefined'){
    alert("鼠标操作");
    }else{
    alert("键盘操作");
    }
    }function bbb(obj){
    if(event.keyCode==9){
    obj.hasblur = true;
    }
    }
    function ccc(obj){
    obj.removeAttribute("hasblur");
    }
    </script></head><body>
    <input id=t type=text value="" onblur="aaa(this)" onkeydown="bbb(this)" onfocus="ccc(this)">
    </body></html>
      

  2.   

    FF好像本身不支持onblur,onfocus事件的...看看有没有其他什么办法解决
      

  3.   

    FF 支持onblur,onfocus事件.
      

  4.   

    想不到这也行。
    原来我是希望,使用事件的参数,例如event.keyCode之类,不过我没试出来。
      

  5.   

    稍微改了下,支持IE和FF
    <html><head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>新建网页 5</title>
    <script>
    window.onload = function (){
    var obj = document.getElementById("t");
    obj.onblur=function (){
    if(obj.hasblur){
    alert("键盘操作");
    }else{
    alert("鼠标操作");
    }
    };
    obj.onkeydown=function (e){
    if(!e) e=event;
    if(e.keyCode==9){
    obj.hasblur = true;
    }
    };
    obj.onfocus=function (){
    obj.hasblur=false;
    };
    }</script></head><body>
    <input id=t type=text value="">
    </body></html>