jq 显示/隐藏 某个模块

html部分

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
    <input class="inp" type="text" >
    <div id="box1">
        content
    </div>
</body>
</html>

  js部分

$(function(){
    /**
     * fn:显示/隐藏级联菜单
     */
    $('.inp').click(function(){
        if($("#box1").css("display")=="none"){
            $("#box1").show();
            }else{
            $("#box1").hide();
            }
    });
    $(document).click(function(e){
        var target = $(e.target);
        if(target.closest(".inp").length != 0) return;
        $("#box1").hide()
        
    })
})

  

猜你喜欢

转载自www.cnblogs.com/xuwupiaomiao/p/12185908.html
jq