Javascript body OnClick

后端 未结 3 1178
攒了一身酷
攒了一身酷 2021-02-20 13:33

I\'m in the process of learning Javascript and I\'m trying to create a simple dropdown menu. An example of my desired functionality can be seen on the google homepage in the top

3条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-20 14:11

    Here is more or less the logic we use in our web app for drop down menus:

    
    
        
    
    
        
    Show menu

    The trick is to use an input field that has the focus, and when it looses it an onblur is triggered and close the menu.

    The mouseover, mouseout are there to prevent the onblur to fire when the user click an item in the menu.

    To have a toggle effect like an open/close on the link, I guess 2 links that hide each other are needed.

提交回复
热议问题