[Toggle.htm]



<!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>

    <title>toggle() 메서드로 토글링</title>

    <style type="text/css">

        .hidden { display:none; }

    </style>

    <script src="js/jquery-1.3.2-vsdoc2.js" type="text/javascript"></script>

    <script type="text/javascript">

        $(document).ready(function () {

            // .toggle(fn1, fn2); // fn1 fn2를 서로 토글링한다...

            $("#btn").toggle(

                function () { $('#myLayer').addClass("hidden"); },

                function () { $('#myLayer').removeClass("hidden"); }

            );

        });   

    </script>

</head>

<body>

    <h1>버튼을 클릭할 때마다 레이어 보이기/숨기기</h1>

   

    <input id="btn" type="button" value="버튼" />

   

    <div id="myLayer" style="background-color:Yellow;">

    안녕

    </div>

</body>

</html>

 




-------------------------------------------------------------------------------------




[실행결과]

--> '버튼'을 누르기 전 화면.('버튼'아래에 있는 레이어에 노란색배경으로 '안녕'이라는 텍스트가 쓰여져 있다.)




--> '버튼'을 누른후 화면('버튼'아래에 있던 노란색배경으로 '안녕'이라는 텍스트가 쓰여져 있던 레이어 부분이 사라졌다.). 다시 '버튼'을 클릭하면 사라졌던 레이어부분이 다시 출력된다. '버튼'을 누를 때마다 교대로 레이어부분이 나타났다가 사라졌다가 한다.(= 토글링)





Posted by holland14
: