Events - Trigger() 메서드 (동적으로 다른 이벤트 호출)
.NET프로그래밍/jQuery 1.3.2 2009. 11. 12. 08:29 |
[Trigger.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>동적으로 다른 이벤트 호출</title>
<script src="../js/jquery-1.3.2-vsdoc2.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
//[1] btn 클릭 이벤트 처리
//$('#btn').click(function () { alert('버튼이 클릭'); });
//[2] 페이지 로드시 버튼 클릭
//$('#my .hover').click(function() { alert('test'); });
//[3] one 메서드
//$('#my input[type=button').one("click", function () {
//alert('역시 버튼이 사용자에 의해서 클릭됨');
//[4] bind메서드
$('#btn').bind("click", function () { alert('버튼 클릭됨'); });
//[!] 페이지 로드시 사용자의 반응이 아닌 코드에 의해서 click 이벤트를 실행
$('#btn').trigger("click"); // 실행하자마자 click 이벤트를 트리거함...
});
</script>
</head>
<body>
<div id="my">
<input type="button" id="btn" value="버튼" class="hover" />
</div>
</body>
</html>
-------------------------------------------------------------------------------------
[실행결과]
--> 아래그림은 위의 [Trigger.htm]소스코드에서 "[4]주석과, [!]주석"에 해당하는 결과임.([4]주석에서 "click"이벤트가 "Bind() 메서드"로 '바인딩'되어서, [!]주석아래의 코드부분에서 실행하자마자 "click 이벤트"를 Trigger한다. 즉, 페이지 로드시 사용자의 반응이 아닌 코드에 의해서 click 이벤트가 실행된다. )
'.NET프로그래밍 > jQuery 1.3.2' 카테고리의 다른 글
Effects - Show() / Hide() 메서드 (보이기 및 숨기기) (0) | 2009.11.12 |
---|---|
Events - Unbind() 메서드 (이벤트 처리기 해제) (0) | 2009.11.12 |
CSS - OuterWidth() / OuterHeight() 메서드 (검색된 요소의 크기 구하기) (0) | 2009.11.11 |
CSS - Width() / Height() 메서드 (검색된 요소의 크기 구하기) (0) | 2009.11.11 |
Manipulation - Remove() 메서드 (검색된 요소를 완전 제거) (0) | 2009.11.11 |