onclick() and onblur() ordering issue

前端 未结 6 1933
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-04 14:52

I have an input field that brings up a custom drop-down menu. I would like the following functionality:

  • When the user clicks anywhere outside the input field,
6条回答
  •  我在风中等你
    2020-12-04 15:40

    Replace on onmousedown with onfocus. So this event will be triggered when the focus is inside the textbox.

    Replace on onmouseup with onblur. The moment you take out your focus out of textbox, onblur will execute.

    I guess this is what you might need.

    UPDATE:

    when you execute your function onfocus-->remove the classes that you will apply in onblur and add the classes that you want to be executed onfocus

    and

    when you execute your function onblur-->remove the classes that you will apply in onfocus and add the classes that you want to be executed onblur

    I don't see any need of flag variables.

    UPDATE 2:

    You can use the events onmouseout and onmouseover

    onmouseover-Detects when the cursor is over it.

    onmouseout-Detects when the cursor leaves.

提交回复
热议问题