toggle() 메서드로 토글링
.NET프로그래밍/jQuery 1.3.2 2009. 11. 6. 11:33 |[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>
-------------------------------------------------------------------------------------
[실행결과]
--> '버튼'을 누르기 전 화면.('버튼'아래에 있는 레이어에 노란색배경으로 '안녕'이라는 텍스트가 쓰여져 있다.)
--> '버튼'을 누른후 화면('버튼'아래에 있던 노란색배경으로 '안녕'이라는 텍스트가 쓰여져 있던 레이어 부분이 사라졌다.). 다시 '버튼'을 클릭하면 사라졌던 레이어부분이 다시 출력된다. '버튼'을 누를 때마다 교대로 레이어부분이 나타났다가 사라졌다가 한다.(= 토글링)
'.NET프로그래밍 > jQuery 1.3.2' 카테고리의 다른 글
hover()로 마우스오버와 아웃을 동시 처리 (0) | 2009.11.06 |
---|---|
toggleClass() 메서드로 CSS 클래스에 대한 토글링 (0) | 2009.11.06 |
slice() 메서드로 지정된 개체만 가져오기 (0) | 2009.11.06 |
filter() 메서드를 사용해서 조건에 맞는 요소만 가져오기 (0) | 2009.11.06 |
특정 요소에 클릭 이벤트를 적용 (0) | 2009.11.06 |