jQuery event.dataプロパティ
例
各 <p> 要素に対して、on() メソッドで渡されたデータを返します:
$("p").each(function(i){
$(this).on("click",{x:i},function(event){
alert("番号:" + $(this).index() + ". 段落のデータは: " + event.data.x);
});
});
$(this).on("click",{x:i},function(event){
alert("番号:" + $(this).index() + ". 段落のデータは: " + event.data.x);
});
});
試してみる »
定義と使用法
event.data プロパティには、現在実行中のハンドラーがバインドされたときにイベントメソッドに渡されたオプションのデータが含まれます。
構文
event.data
| パラメータ | 説明 |
|---|---|
| event | 必須です。eventパラメータはイベントバインド関数から取得されます。 |
その他の拡張
jQuery イベントメソッド