Architect's Log

I'm a Cloud Architect. I'm highly motivated to reduce toils with driving DevOps.

【jQuery】複数のイベントにハンドラをバインドする

ソースコード
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
</head>
<body>
<input id="binding" type="button" value="bind" />
<input type="button" value="dummy" />
</body>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.js"></script>
<script type="text/javascript">
(function ($) {
	$(document).ready(function () {
		// スペース区切りで複数のイベントを指定できる
		$('#binding').bind('click blur', function (e) {
			alert('event');
		});
	});
})(jQuery);
</script>
</html>
実行結果


bindボタンクリック時とdummyボタンへの遷移時にイベントが発生しました。