one(type, [data], fn)
version 1.1 以降
解説
マッチした要素に、1度だけ実行されるイベントハンドラをバインドします。
1度だけ実行されるということ以外は、bind(type, [data], fn)と同じです。詳細は、bind(type, [data], fn)を参照してください。
引数
-
type
String: バインドするイベントを表す文字列。標準では以下のイベントが定義されています。
"blur", "focus", "load", "resize", "scroll", "unload", "click", "dblclick", "mousedown", "mouseup", "mousemove", "mouseover", "mouseout", "mouseenter", "mouseleave", "change", "select", "submit", "keydown", "keypress", "keyup", "error"
上記の他にも、ユーザ定義のカスタムイベントをバインドすることができます。
また、イベント種別文字列をスペースで区切り指定することによって、複数のイベントに同じイベントハンドラを一度に指定することができます。
$("p").bind("click dblclick", function(event){
});
-
[data]オプション
Object: イベントハンドラに渡すデータ。イベントオブジェクトのdata プロパティで参照。
-
fn
Function: バインドするイベントハンドラ関数。この関数には2つの引数が渡されます。
引数 |
説明 |
event |
イベントオブジェクト。バインド時に渡されたデータは、data プロパティで参照。 |
triggerData |
イベント実行時に渡されたデータ。 |
戻り値
関連
例
例1:文字列をクリックすると、1回限りアニメーションします。
$("li").one(
"click",
function(){
$(this).animate({fontSize: "2em"}, "slow", function() {
$(this).animate({fontSize: "1em"}, "slow", function(){
$(this).css("background-color", "#c0c0c0").append(" <--実行済み");
});
});
}
);
例1
- jQuery
- prototype.js
- Ext
- script.aculo.us
- YUI
|
- jQuery API 1.4.4 日本語リファレンス
- Core
- Selectors
- Attributes
- Traversing
- Manipulation
- CSS
- Events
- イベントオブジェクト
- bind(type, [data], fn)
- bind(events)
- blur()
- blur(fn)
- change()
- change(fn)
- click()
- click(fn)
- dblclick()
- dblclick(fn)
- delegate(selector, eventType, [eventData], handler)
- die(eventType, [handler])
- error()
- error(fn)
- jQuery.Event(src)
- focus()
- focus(fn)
- focusin(fn)
- focusout(fn)
- hover(over, out)
- keydown()
- keydown(fn)
- keypress()
- keypress(fn)
- keyup()
- keyup(fn)
- live(eventType, [eventData], handler)
- load(fn)
- mousedown(fn)
- mouseenter(fn)
- mouseleave(fn)
- mousemove(fn)
- mouseout(fn)
- mouseover(fn)
- mouseup(fn)
- one(type, [data], fn)
- ready(fn)
- resize(fn)
- scroll(fn)
- select()
- select(fn)
- submit()
- submit(fn)
- toggle(fn, fn2, [fn3, fn4,...])
- trigger(type, [data])
- triggerHandler(type, [data])
- unbind([type], [fn])
- undelegate(selector, eventType, [handler])
- unload(fn)
- Effects
- Ajax
- Utilities
- jQuery UI API 1.8.4 日本語リファレンス
- jQueryと他のライブラリを同時に使用する方法
|