弹出框出来之后敲击enter键问题
2010-09-15 18:10
260 查看
往往点击弹出对话框之后触发焦点仍然为此焦点,此时用户点击enter键仍然会触发对象在此弹出对话框,由于一些历史原因修改此bug只能在对话框对象方法中进行;
刚开始想简单的像使其焦点改变为别的对象:
document.body.focus();
使其body获得焦点即可,因为body肯定会有的;
实验得知IE可以 firefox不可以啊;查货得知不是所有的标签都支持focus事件:
让后改变为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();
}
这样都满足了要求;
刚开始想简单的像使其焦点改变为别的对象:
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();
}
这样都满足了要求;
相关文章推荐
- jquery Jbox 插件实现弹出窗口在修改的数据之后,关闭弹出窗口刷新父页面的问题
- 弹出层中回车(Enter键)导致页面刷新的问题
- 安装plsql之后弹出框nls_lang is not defiend,sql 数据查出来中文乱码
- 解决Xcode8之后代码有冲突时自带git工具不出来解决conflict的面板的问题
- 解决爱加密加固之后使用xposed hook的时候log打印不出来的问题
- 弹出框确定之后刷新页面的问题
- 装了win8 之后QQ音乐跟酷狗乐库都显示不出来的问题
- 最近升级了Xcode4.2,结果编译之后发现程序的很多地方都不能用,或者出问题,所以结合网友们的情况把遇见的列出来:
- 三十,iOS当使用运行时替换了NSArrary的方法之后,弹出键盘进入后台然后在进入前台会出现崩溃的问题
- TortoiseSVN checkout 之后图标(绿色勾之类的)没有显示出来的问题
- highcharts只显示数据,无线条,但是F12之后,会出来线条的问题。
- SVN checkout 之后图标(绿色勾之类的)没有显示出来的问题
- TortoiseSVN checkout 之后图标(绿色勾之类的)没有显示出来的问题
- jquery Jbox 插件实现弹出窗口在修改的数据之后,关闭弹出窗口刷新父页面的问题
- 解决爱加密加固之后使用xposed hook的时候log打印不出来的问题
- EditText焦点问题:进入app之后,就弹出软键盘
- TortoiseSVN checkout 之后图标(绿色勾之类的)没有显示出来的问题
- form中的button按钮在IE11中自动提交表单问题导致弹出框关闭之后表单被重置
- form中的button按钮在IE11中自动提交表单问题导致弹出框关闭之后表单被重置
- form中的button按钮在IE11中自动提交表单问题导致弹出框关闭之后表单被重置