.trigger()
最后更新于:2022-04-02 03:21:52
[TOC]
## .trigger()
进行手动触发
### 语法
```
.trigger( eventType [, extraParameters ] )
```
### 示例
#### hello world
```
$(".div1").on("myCustomEvent", function (event, myName) {
console.log(myName);//{name:"idcpj"}
})
$(".div1").on("click",function (event) {
$(this).trigger("myCustomEvent",{name:"idcpj"})
})
```
#### 触发表单
```
$("form:first").trigger("submit")
```
#### 向事件中传入任意的数据
```
$("p").click( function (event, a, b) {
// when a normal click fires, a and b are undefined
// for a trigger like below a refers to "foo" and b refers to "bar"
} ).trigger("click", ["foo", "bar"]);
```
';