auto-complete search suggestion drop-down popup

前端 未结 3 1301
南旧
南旧 2021-01-24 08:08

Im trying to make a popup div (when a text-box value changes) and it can be closed (visibility: none) by clicking anywhere outside the div. Similar to Google suggestion drop-dow

3条回答
  •  南笙
    南笙 (楼主)
    2021-01-24 08:30

    Here's an example with jQuery. If you click on the "test" text, you make the other text appear. Clicking anywhere else except than on the newly appeared text makes it disappear.

    This works because if the click happened inside (the .toggle object, in this case), we call e.stopPropagation() for the click event to stop propagating further up towards the entire window. However if the click occurred somewhere else, it propagates directly to the window and makes .toggle disappear.

    See example of it working on jsfiddle.

    
    
    
    test
    
    asdasdsa

提交回复
热议问题