|
||||
|
||||
イベントオブジェクト
解説jQueryのイベントオブジェクトは W3Cの規格に基づいて標準化されています。 type, target, pageX/Yプロパティと、stopPropagation(), preventDefault()メソッドを提供します。 イベントオブジェクトは、イベントハンドラの引数として渡されます。
また、バインド時に渡されたデータは、 プロパティメソッド
関連type
イベントの種別を表す文字列です。 $("#test_type").click(function(event){ alert("event.type: " + event.type); }) テスト1 id=test_type target
イベント対象のDOM要素です。 $("#test_target").click(function(event){ var buff = []; $.each(event.target, function(key, value){ buff.push(key + ":" + value); }); $("p.display").text("[" + buff.join(", ") + "]"); }); テスト2 id=test_target div要素
p要素 pageX/Y
イベントが発生した時のマウスポインタの位置です。 $("#test_pageX_Y").click(function(event){ alert("event.pageX: " + event.pageX + "\n" + "event.pageY: " + event.pageY); }) テスト3 id=test_pageX_Y stopPropagation()
イベントの伝播(バブリング)を停止します。 $("#parent").click(function(event){ alert(event.target.id=="parent" ? "parent clicked!" : "click event bubbling!"); }); $("#def").click(function(event){ alert("default clicked!"); }); $("#spp").click(function(event){ alert("stopPropagation clicked!"); event.stopPropagation(); }); テスト4
parent (id="parent")
default (id="def")
stopPropagation (id="spp")
preventDefault()
標準のアクションを停止します。 $("#prd").click(function(event){ event.preventDefault(); }) |
|
|||
© 2007-2008 by いけまさ. All rights Reserved. ![]() | ||||