往往点击弹出对话框之后触发焦点仍然为此焦点,此时用户点击enter键仍然会触发对象在此弹出对话框,由于一些历史原因修改此bug只能在对话框对象方法中进行;
刚开始想简单的像使其焦点改变为别的对象:
document.body.focus();

使其body获得焦点即可,因为body肯定会有的;
实验得知IE可以 firefox不可以啊;查货得知不是所有的标签都支持focus事件:

支持该事件的 HTML 标签:

<a>, <acronym>, <address>, <area>, <b>, <bdo>, <big>, <blockquote>, <button>, <caption>, <cite>, <dd>, <del>, <dfn>, <div>, <dl>, <dt>, <em>, <fieldset>, <form>, <frame>, <frameset>, <h1> to <h6>, <hr>, <i>, <iframe>, <img>, <input>, <ins>, <kbd>, <label>, <legend>, <li>, <object>, <ol>, <p>, <pre>, <q>, <samp>, <select>, <small>, <span>, <strong>, <sub>, <sup>, <table>, <tbody>, <td>, <textarea>, <tfoot>, <th>, <thead>, <tr>, <tt>, <ul>, <var>

支持该事件的 JavaScript 对象:

button, checkbox, fileUpload, layer, frame, password, radio, reset, select, submit, text, textarea, window


 让后改变为window.focus();让后再window.blur()可以;但发现使用IE6的时候他的blur会使其改变窗口,不满足要求;
于是按照麻烦的来了,先找到其触发对象让后使其blur();
写成:
try{
   var getEvent=function(){ 
   if (window.event) return window.event; 
   var c = getEvent.caller; 
   while (c.caller) c = c.caller; 
   return c.arguments[0]; 
   }
   var e=getEvent();
   var target=e.target||e.srcElement;
   target.blur();
    }
   catch(error){
  document.body.focus();
   }
这样都满足了要求;

posted on 2010-09-15 18:10  星光~  阅读(481)  评论(0编辑  收藏  举报