Home >Web Front-end >JS Tutorial >Usage examples of trigger() method in jQuery_jquery

Usage examples of trigger() method in jQuery_jquery

WBOY
WBOYOriginal
2016-05-16 16:19:141071browse

The example in this article describes the usage of the trigger() method in jQuery. Share it with everyone for your reference. The specific analysis is as follows:

This method triggers an event of the specified type for the matching element.

Grammar structure 1:
Specifies the event type that is triggered by the matching element.

Copy code The code is as follows:
$(selector).trigger(event,param1,param2,.. .)

Parameter list:

参数 描述
event 规定指定元素要触发的事件。
可以是自定义事件(使用 bind() 函数来附加),或者任何标准事件。
param 可选。传递到事件处理程序的额外参数。
额外的参数对自定义事件特别有用。

Example code:

Copy code The code is as follows:






trigger() function-Script Home









When the button button is clicked, the click event on the div can be triggered, and then the click event processing function can be executed.

Grammar structure 2:

Use the event object as a parameter to specify the event type to be triggered for the matching element.

Copy code The code is as follows:
$(selector).trigger(eventObj)

Parameter list:

参数 描述
eventObj 事件对象规定了事件发生时运行的函数。

Example code:

Copy code The code is as follows:






trigger() function-Script Home









I hope this article will be helpful to everyone’s jQuery programming.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn