简体   繁体   English

Alt按键上的聚焦事件无法按预期进行

[英]focusout event on alt keypress does not work as expected

I am using jQuery Token Input plugin with one of my custom written plugins in one of my projects. 我在一个项目中将jQuery Token Input插件与一个自定义书面插件一起使用。

My plugin basically adds an anchor tag to an element that it was initialized on and upon clicking the anchor link a text input element is shown which is bound to jquery token input plugin. 我的插件基本上向在其上初始化的元素添加了一个锚标记,并且在单击锚链接后,显示了一个文本输入元素,该文本绑定到jquery token input插件。

On FocusOut event i want to hide the text input (in this case which would be a ul initialized by jquery token input in place of the text input). FocusOut事件上,我想隐藏文本输入(在这种情况下,这将是由jQuery令牌输入代替文本输入初始化的ul )。

All works fine till now. 到目前为止一切正常。

But if I press the alt key, the main ul is hidden as expected but the dropdown ul is still visible. 但是,如果按alt键,则主ul会按预期隐藏,但下拉ul仍然可见。

To see the problem that i am facing you can also view this JSFiddle . 要了解我面临的问题,您还可以查看此JSFiddle Sorry, about the CSS part, i did include the CSS file but for some reason it does not work as expected. 抱歉,关于CSS部分,我确实包含了CSS文件,但是由于某种原因,它无法按预期工作。

Now, in the fiddle if you click the + Add button the input and the dropdown (with instructions) appears, then if you click anywhere else in the preview window, it disappears, which is what is expected behaviour. 现在,在小提琴中,如果单击+ Add按钮,将显示输入内容和下拉列表(带有说明),然后在预览窗口中的其他任何位置单击它,则该内容消失,这是预期的行为。

But if you click on the add button and once the input and dropdown appears and then if you press the alt key (which initiates the focusout event) the input disappears but the dropdown still shows. 但是,如果单击添加按钮,则一旦出现输入和下拉菜单,然后按alt键(启动聚焦事件),输入就会消失,但下拉菜单仍会显示。 Why is that ? 这是为什么 ?

What could be the reason causing this ? 可能是什么原因造成的?

Update: 更新:

I apologize if I made it a little complicated. 如果让事情变得有点复杂,我深表歉意。 Following is comparison between the expected behavior and the problem. 以下是预期行为和问题之间的比较。

Case 1: (focusout event triggered by clicking somewhere in the body). 情况1 :(通过单击身体某处触发聚焦事件)。

In this case, A user clicks on the +Add button > An input box appears with an open dropdown > A user focuses out by clicking somewhere else in the body > The Input and dropdown disappears. 在这种情况下,用户单击+添加按钮>将出现一个带有打开的下拉列表的输入框>用户通过单击正文中的其他位置来进行聚焦>输入和下拉列表将消失。

This is the expected behaviour. 这是预期的行为。

Case 2: (focusout event triggered on alt keypress). 情况2 :(在alt按键上触发了对焦事件)。

In this case, A user clicks on the +Add button > An input box appears with an open dropdown > A user presses the alt key which triggers the focusout event > The Input disappears but dropdown does not. 在这种情况下,用户单击+添加按钮>将出现一个带有打开的下拉列表的输入框>用户按下alt键触发触发焦点事件>输入消失,但下拉列表没有。

I need to make sure the dropdown disappears in this case too. 在这种情况下,我还需要确保下拉列表也消失。

Note: The Dropdown CSS is messed up in the fiddle for some reason. 注意:由于某些原因,Dropdown CSS混乱不堪。 The text that says type somethig is the dropdown element. type somethig的文本是下拉元素。

Add shortcut library and add the following code . 添加快捷方式库并添加以下代码。 It works 有用

shortcut.add("Alt", function() {
   $('.token-input-dropdown').hide()
        });

Demo : http://jsfiddle.net/abdennour/dHSWu/5/ 演示: http : //jsfiddle.net/abdennour/dHSWu/5/

Likewise,be kept away the tags using margin to avoid overlapping of events 同样,请使用margin使标签远​​离,以避免事件重叠

a.addInput{
    margin:2px;
}
div.token-input-dropdown{
     margin:2px;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM