jQuery bind()メソッド

❮jQueryイベントメソッド

クリックイベントを<p>要素にアタッチします。

$("p").bind("click", function(){
  alert("The paragraph was clicked.");
});

定義と使用法

bind()メソッドはバージョン3.0で非推奨になりました。代わりにon()メソッドを使用し てください。

 bind()メソッドは、選択した要素に1つ以上のイベントハンドラーをアタッチし、イベントが発生したときに実行する関数を指定します。


構文

$(selector).bind(event,data,function,map)

Parameter Description
event Required. Specifies one or more events to attach to the elements.

Multiple event values are separated by space. Must be a valid event.
data Optional. Specifies additional data to pass along to the function
function Required. Specifies the function to run when the event occurs
map Specifies an event map ({event:function, event:function, ...}) containing one or more events to attach to the elements, and functions to run when the event occurs

自分で試してみてください-例


を添付する要素に複数のイベントを添付する方法。


使用イベントマップを使用して、選択した要素に複数のイベント/関数をアタッチする方法。


にデータを渡すカスタムの名前付きイベントハンドラーにデータを渡す方法。


❮jQueryイベントメソッド