element.on()
Use the
element.on()
or element.once()
method to register event listeners for the Element instance. Depending on your business needs, perform one of the following actions:- If continuous listening is needed, call element.on()to register continuous listening, where the callback function is executed each time the event is triggered
- If you want the event to be handled only once, call element.once()to register one-time listening, where the listener is automatically canceled after the event is triggered once.
Note: Event names and specific data structures may vary slightly depending on product form and integration scenario. The following lists only typical usage.
Method signature
When calling this method, please use the following standard method signature format.
JavaScript
TypeScript
Parameters
error event
Used to monitor the web page loaded by the SDK, which contains the following parameters:
Return value
- element.on(): Returns anoffFunction. Calling this function will unregister the event listener.
- element.once(): No return value. The listener is automatically unregistered after the event is triggered once.
Error codes
The following are the relevant error codes captured when calling the
element.on()
method.element.mount() related
antom.createElement() related
antom.confirmCardSetup() related
Best practices
- Event name case rules: Please strictly pass in the event name as defined in the documentation or SDK.
- Multiple registrations: Calling element.on()multiple times for the same event will register multiple listeners, all of which will be triggered in the order they were registered. If no longer needed, please manage them according to business needs or cancel listening through other APIs.
- Destruction timing: After calling or , the event listeners for the corresponding Element will no longer be effective.