.one() 触发一次
最后更新于:2022-04-02 03:21:49
[TOC]
## .one
- 处理函数在每个元素上每种事件类型最多执行一次
- 原理为处理后使用off删除绑定
```
$("#foo").one("click", function() {
alert("This will be displayed only once.");
});
```
等效于
```
$( "#foo" ).on( "click", function( event ) {
alert( "This will be displayed only once." );
$( this ).off( event );
});
```
### 语法
```
.one( events [, data ], handler(eventObject) )
.one( events [, selector ] [, data ], handler(eventObject) )
.one( events [, selector ] [, data ] )
```
### 示例
```
$("#foo").one("click", function() {
alert("This will be displayed only once.");
});
```
';