Not trigger any events (e.g. click) when a specific input field loses focus
Let's say I have an input text field and a few anchor links.
The user cursor is focused in the input text field.
When the user clicks on one of the links outside this field, the input field loses focus and a click event is triggered (bad - I just want the first click outside to be an action to lose the focus of that input field).
Only subsequent clicks would be triggered once this input field is no long开发者_运维技巧er in focus.
You should use onblur event listener on the text field that will put a flag to indicate that user just left this "magic" input. Then, check this flag in "onclick" events in anchors and if the flag is true, call "prevent default" (and/or return the focus to the input). Optionally clear the flag after a small timeout.
精彩评论