auto-complete search suggestion drop-down popup

前端 未结 3 1298
南旧
南旧 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:15

    The jquery solution would be

    $("body > div").click(function() {
    if ($(this).attr("id") == "div-id") {
        // inside the DIV
    } else {
        // not inside the DIV
    }
    });
    

    or

    $("html").click(function (e)
    {
    if (e.target == document.getElementById("div-id"))
        alert("Inside DIV");
    else
        alert("Outside DIV!");
    });
    

    or Javascript snippet would be something like this:

    
    

提交回复
热议问题