 |
|
|  |
jQuery Event - bind() ¸Þ¼µå¸¦ ÅëÇÑ À̺¥Æ® ¿¬°á |
|
|
 |
8³â Àü |
.bind() ¸Þ¼µå´Â ¸» ±×´ë·Î °³Ã¼¿Í À̺¥Æ®¸¦ ¹¾îÁÖ´Â ¿ªÇÒÀ» ÇÕ´Ï´Ù.
¾Õ¿¡¼ ÁøÇàÇÑ event °ü·Ã ¸Þ¼µåÀÇ °æ¿ì ÇØ´ç ¸Þ¼µå¸¦ Á÷Á¢ È£ÃâÇÏÁö¸¸, bind()ÀÇ °æ¿ì ÆĶó¹ÌÅÍÀÇ °ªÀ¸·Î À̺¥Æ® À̸§À» ³ÖÀ½ À¸·Î½á ÇØ´ç À̺¥Æ®¸¦ üũÇÏ°Ô µË´Ï´Ù.
$(¡°div¡±).click(function() { alert('click¡¯); }
$(¡°div¡±).click(function() { alert(¡®click¡¯); }
event ¸Þ¼µå¿¡¼ ÀÌ·¸°Ô »ç¿ëÇß´Ù¸é, bind() ¸Þ¼µå¸¦ ÅëÇؼ´Â ´ÙÀ½°ú °°ÀÌ Ç¥Çö µË´Ï´Ù.
$(¡°div¡±).bind(??click¡¯, function() { alert('bind click¡¯); }
$(¡°div¡±).bind(¡®click¡¯, function() { alert(¡®bind click¡¯); }
µÎ ¸Þ¼µåÀÇ Â÷ÀÌÁ¡ÀÌ º¸À̽óª¿ä ?
.click() ¸Þ¼µåÀÇ Á÷Á¢È£ÃâÀÌ ¾Æ´Ñ ÇØ´ç À̺¥Æ®ÀÇ À̸§À» ³Ñ±èÀ¸·Î ½á µ¿ÀÏÇÑ È¿°ú¸¦ ¾òÀ» ¼ö ÀÖ½À´Ï´Ù.
ÀÌ·¯ÇÑ ±â´ÉÀ» ÅëÇØ Á¶°Ç¿¡ µû¶ó ¸Å¿ì °£´ÜÈ÷ À̺¥Æ®¸¦ µ¿ÀûÀ¸·Î ÇÒ´ç ÇÒ ¼ö ÀÖ½À´Ï´Ù. ¶ÇÇÑ, ¿©·¯ °¡ÁöÀÇ À̺¥Æ®¸¦ ¼Õ½±°Ô ¼±ÅÃÇÑ °³Ã¼¿¡ Àû¿ëÇÒ ¼ö ÀÖ½À´Ï´Ù. µÎ °³ÀÇ À̺¥Æ®¸¦ Àû¿ëÇÑ ´ÙÀ½ ¿¹Á¦¸¦ ÅëÇØ Á»´õ ÀÚ¼¼È÷ ¾Ë¾Æ º¸µµ·Ï ÇÏ°Ú½À´Ï´Ù.
À̹ø ¿¹Á¦´Â ¸¶¿ì½ºÀÇ Æ÷ÀÎÅÍ°¡ ÁöÁ¤ÇÑ ¿ä¼Ò¿¡ µé¾î ¿ÔÀ» ¶§¿Í, ³ª°¬À» ¶§ÀÇ À̺¥Æ®¸¦ üũÇÏ¿© »óŸ¦ Ç¥½ÃÇϸç, bind()¿¡ ¡°mouseenter, mouseleave¡± À̺¥Æ®¸¦ ÀÌ¿ëÇÏ¿´½À´Ï´Ù.
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>jQuery</title>
<link href="../Styles/Site.css" rel="stylesheet" type="text/css" />
<style>
div,pre { background : #FFF; padding:10px; margin:10px; }
table { border:1px solid #AAA; }
td { border:1px solid #AAA; width:25px; height:25px; }
.selected { font-weight:bold; color:White; background-color : Red;}
</style>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
var count = 0;
$(document).ready(function () {
$("#mouseArea").bind("mouseenter mouseleave", function (e) {
count++;
$("#spResult").text(count + " enter or leave ");
});
});
</script>
</head>
<body style="padding:10px;">
<h2>jQuery ½ÃÀÛ Selector</h2>
<p>jQuery¿¡ ´ëÇÑ ÀÚ¼¼ÇÑ ³»¿ëÀ» º¸·Á¸é jquery.com À» ¹æ¹®Çϼ¼¿ä.</p>
<div id="mouseArea">
AREA(DIV)
MOUSE : <span id="spResult"></span>
</div>
</body>
</html>
¸¶¿ì½º Æ÷ÀÎÅ͸¦ À§Ä¡ÇÒ ¶§ ¸¶´Ù Ä«¿îÅÍ°¡ ¿Ã¶ó°¡´Â °ÍÀ» È®ÀÎ ÇÒ ¼ö ÀÖ½À´Ï´Ù. ÀÌ·¸°Ô ¿©·¯ °³ÀÇ À̺¥Æ®¸¦ ÁöÁ¤ ½Ã¿¡µµ ¹®Á¦¾øÀÌ µ¿ÀÛÀ» ÇÏ´Â°É È®ÀÎ ÇÒ ¼ö ÀÖ½À´Ï´Ù.
À̹ø¿¡´Â ÀÌ·¸°Ô º¹¼öÀÇ À̺¥Æ®¸¦ ÁöÁ¤ ÈÄ °¢°¢ÀÇ À̺¥Æ®¿¡ µû¸¥ ´Ù¸¥ µ¿ÀÛÀ» ±¸ÇöÀ» Çϱâ À§Çؼ´Â ¾î¶°ÇÑ ¹æ¹ýÀÌ ÀÖ´ÂÁö ¾Ë¾Æ º¸µµ·Ï ÇÏ°Ú½À´Ï´Ù. bind() ¸Þ¼µå¿¡¼ ¸Å¿ì Áß¿äÇÑ ºÎºÐÀÌ´Ï ÁÖÀÇ ±í°Ô º¸½Ã±â ¹Ù¶ø´Ï´Ù.
´ÙÀ½ ¿¹Á¦¿¡¼´Â bind() ¸Þ¼µåÀÇ ÆĶó¹ÌÅÍ¿Í eventData¸¬ »ç¿ëÇÏ¿© °¢°¢ÀÇ À̺¥Æ®¸¦ ¾î¶»°Ô È®ÀÎÇÏ°í ó¸®ÇÏ´ÂÁö ¾Ë¾Æ º¸µµ·Ï ÇÏ°Ú½À´Ï´Ù.
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>jQuery</title>
<link href="../Styles/Site.css" rel="stylesheet" type="text/css" />
<style>
div,pre { background : #FFF; padding:10px; margin:10px; }
table { border:1px solid #AAA; }
td { border:1px solid #AAA; width:25px; height:25px; }
.selected { font-weight:bold; color:White; background-color : Red;}
</style>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
var countEnter = 0;
var countLeave = 0;
$(document).ready(function () {
$("#mouseArea").bind("mouseenter mouseleave", function (e) {
if (e.type == 'mouseenter') {
countEnter++;
$("#spResult").text(countEnter + " MouseEnter");
}
else {
countLeave++;
$("#spResult").text(countLeave + " MouseLeave ");
}
});
});
</script>
</head>
<body style="padding:10px;">
<h2>jQuery ½ÃÀÛ Selector</h2>
<p>jQuery¿¡ ´ëÇÑ ÀÚ¼¼ÇÑ ³»¿ëÀ» º¸·Á¸é jquery.com À» ¹æ¹®Çϼ¼¿ä.</p>
<div id="mouseArea">
AREA(DIV)
MOUSE : <span id="spResult"></span>
</div>
</body>
</html>
°¢°¢ÀÇ À̺¥Æ®¿¡ µû¶ó °ªÀÌ º¯°æµÇ´Â°É È®ÀÎ ÇÒ ¼ö ÀÖ½À´Ï´Ù.
<script type="text/javascript">
var countEnter = 0;
var countLeave = 0;
$(document).ready(function () {
$("#mouseArea").bind({
mouseenter : function() {
countEnter++;
$("#spResult").text(countEnter + " MouseEnter");
},
mouseleave : function() {
countLeave++;
$("#spResult").text(countLeave + " MouseLeave ");
}
});
});
</script>
À§ ¼Ò½º¿¡¼ ½ºÅ©¸³Æ® ºÎºÐ¸¸ º¯°æÇÏ¿´À¸¸ç, eventData ´ë½Å¿¡ °¢°¢ÀÇ À̺¥Æ®¿¡ °ü·Ã ÇÔ¼ö¸¦ ¿¬°áÇÏ¿© ÇØ´ç À̺¥Æ®¸¦ ±¸ºÐ ¢°í ÀÖ½À´Ï´Ù.
¿ª½Ã³ª µ¿ÀÏÇÑ µ¿ÀÛÀ» ÇÏ°í ÀÖ´Â ¸ð½ÀÀ» È®ÀÎ ÇÒ ¼ö ÀÖ½À´Ï´Ù. |
|
̵̧ : 387 |
̵̧
¸ñ·Ï
|
|
|  |
|