您的位置:首页 > 其它

弹出框出来之后敲击enter键问题

2010-09-15 18:10 260 查看
往往点击弹出对话框之后触发焦点仍然为此焦点,此时用户点击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();
}
这样都满足了要求;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐