javascript  怎么用if判断文本框是否获得焦点
if(Myform.document.getElementById("accountid").focus()){
document.all.accountidDiv.style.display = "none";
}
这样对嘛??
我是新手
谢谢

解决方案 »

  1.   

    设置一个标记,比如
    var flag = false;
    在Myform.document.getElementById("accountid")得到焦点时,把这个标记设置为true,失去焦点时为false
    Myform.document.getElementById("accountid").onfocus=function(){flag = true;};
    Myform.document.getElementById("accountid").onblur=function(){flag = false;};
      

  2.   

    还有一个方法就是把focus绑定到一个function上,估计你的要求就是在得到焦点的时候做一些处理吧?把你的处理代码写在function中就可以啦@_@
      

  3.   

    将focus绑定到function较好,处理的代码写在function中,即直观有易于理解