1. 程式人生 > >Jquery之框的彈出與關閉

Jquery之框的彈出與關閉

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>CheckBox之框的彈出與關閉</title>

<style>
    #box{width:400px; height:100px; background:#D1D1D1; margin:250px auto; display:none;}
    #box #add_http{ color:blue;}
    #box #gb{ color:red; display:block; float:right;}
    #box div{width:400px; height:60px; background:gray; margin:17px auto;}

</style>
<script type="text/javascript" src=".../jquery-3.2.1/jquery-3.2.1.min.js"></script>
<script>
    $(document).ready(function(e) {
        //第一種方法
        //開啟
        $("#on").click(
            function(){
                if($("#box").css('display','block')){

                    //第一種方法
                    //$(this).parent().find("#box").show(300);
                    //第二種方法
                    $(this).siblings("#box").show(300);

                }
            }
        );
        //關閉
        $("#off").click(
            function(){
                if($("#box").css('display','block')){
                    //第一種方法
                    //$(this).parent().find("#box").hide(600);
                    //第二種方法
                    $(this).siblings("#box").hide(600);

                }
            }
        );
        $("#gb").click(
            function(){
                if($("#box").css('display','block')){
                    $(this).parent().hide(600);

            }
        }
        );
        
        //第二種方法
        /*$("#on").click(
            function(){            
                $(this).parent().find("#box").toggle();
            });*/

        
    });
</script>
</head>

<body>
<input type="button" id="on" class="on" value="彈出"/>
<input type="button" id="off" class="off" value="關閉"/>
<div id="box">
    <label id="add_http">新增網站</label>
    <label id="gb">關閉</label>
     <div id="box_head">
        <label>名稱</label><input type="text" />
        &nbsp;&nbsp;&nbsp;
        <label>網站</label><input type="text" />
        <br/>
        <input type="button" value="新增" />
         &nbsp;&nbsp;&nbsp;
         <input type="reset" value="重置" />
    </div>
</div>

</body>

</html>