특정 요소에 클릭 이벤트를 적용
.NET프로그래밍/jQuery 1.3.2 2009. 11. 6. 10:28 |[Click.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>bind() 중 click 이벤트는 click()메서드로 사용</title>
<style type="text/css">
.redColor { color:Red; }
</style>
<script src="js/jquery-1.3.2-vsdoc2.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
// 특정 요소에 클릭 이벤트를 적용 : bind()보다 간편
$('#mainMenu .redColor').click(function() {
if (this.id == "dnk") {
location.href = "http://www.dotnetkorea.com";
}
else if (this.id == "va") {
window.open("http://www.VisualAcademy.com/", "", "");
}
});
});
</script>
</head>
<body>
<div id="mainMenu">
<div id="dnk" class="redColor">닷넷코리아</div>
<div id="va" class="redColor">비주얼아카데미</div>
<div id="ll" class="redColor">라이선스랜드</div>
</div>
</body>
</html>
-------------------------------------------------------------------------------------
[실행결과]
--> 첫 화면
--> 위의 그림에서 '닷넷코리아'텍스트를 클릭하면 해당사이트로 이동함.
--> 맨 위의 그림에서 '비주얼아카데미'텍스트를 클릭하면 또 하나의 '인터넷 창'이 열리면서 해당사이트로 이동함.
'.NET프로그래밍 > jQuery 1.3.2' 카테고리의 다른 글
slice() 메서드로 지정된 개체만 가져오기 (0) | 2009.11.06 |
---|---|
filter() 메서드를 사용해서 조건에 맞는 요소만 가져오기 (0) | 2009.11.06 |
This.id로 DOM 요소의 id 속성 가져오기 (0) | 2009.11.06 |
AddClass / RemoveClass(스타일 추가 / 제거) (0) | 2009.11.06 |
bind() 메서드로 동적으로 이벤트 부여 (0) | 2009.11.06 |