Home > Web Front-end > JS Tutorial > jQuery implements methods to automatically call and trigger an event

jQuery implements methods to automatically call and trigger an event

高洛峰
Release: 2016-12-06 14:44:36
Original
1150 people have browsed it

The example in this article describes how jQuery can automatically call and trigger an event. Share it with everyone for your reference, the details are as follows:

I will take the click event as an example to study this topic:

jQuery automatically triggers the click event

1. For example, if we define a click event through jquery, how can we automatically trigger it? :

$(function(){
   $('#button').click(function(){
     alert('button is clicking!');
   });
})
Copy after login

1) Automatically trigger click events

$('#button').click();
Copy after login

This was beyond my expectation. I thought this would overwrite the previous encapsulation event
In fact, it didn’t. Instead, the anonymous function inside is called,
This way we can easily understand why some functions have both the function of assignment and value acquisition

$('input').val('默认值');
var templete = $('input').val();
Copy after login

In fact, the principle is to put it plainly, it is to directly return the parameters inside.

2) Here is another trigger method:

$('#button').trigger('click');
Copy after login


Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template